Is there a way in ASP.Net MVC, in the controller to access a variable in sessionstorage or localstorage?

Asked

Viewed 1,363 times

3

I need to get the value of a variable stored in sessionstorage through a controller where this method is not passed the parameter of this variable.

Session/localstorage are managed through javascript. Otherwise it is easy to get the value of variables in C# through AJAX and several other ways.

But what I need is the opposite. It has ways?

1 answer

4

You can use the Signaler, which is a project developed by Microsoft so that the server can communicate with the browser, and send information to it, and then back to the server.

It is possible to install Signalr via Nuget:

Install-Package Microsoft.AspNet.SignalR

Or by the Visual Studio package manager.

Signalr is very easy to use, there is a tutorial to use Signalr.

To get a value in the browser, you will have to send a message to the browser, and when listening to this message in the client, send another message to the server, with the desired value.

  • 1

    @Marcosfreitas Glad you liked the answers! But the best way to thank whoever helped you is to mark the best answer and vote for everyone who helped you. So you make sure that whoever wrote the answer gets something in return, in addition to making the site cleaner and more useful for everyone. Adding a new answer like this (which is not an answer to the question) makes the site more confusing and can get in the way.

  • Miguel, can you post a small example? the content of the tutorial only shows an example of chat.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.