4

I have a key value local storage in my browser as shown in the image below. I want to retrieve this information with ASP.NET Core MVC. Once I retrieve it, I could use it for for example storing it in a database for later use.

How can I access this information with ASP.NET Core 3.1 MVC?

Local Storage in browser

//ADDITIONAL INFORMATION// Based on the two answers (Nadeem and Abdelrahman), I did check on this and somehow I think the best way would be to go with Ajax. In another post in Stackoverflow: Passing localstorage to controller using Ajax

I see an example as below:

function sendLocalStorage() {

var JsonLocalStorageObj = JSON.stringify(localStorage);
//var test = ["test1", "test2", "test3"];

$.ajax({
    url: "/MyControllersName/Test",
    type: "POST",
    data: { JsonLocalStorageObj: JsonLocalStorageObj },
    success: function (result) {
        alert(result);
    }
});
}

I wonder though how within this function you can define which localstorage value you will post? I mean how do you select the key for the value that you want to post?

Second, as the server application uses EF identity, I assume some security need to be posted with this request. I checked in the developer tools of the browser, I have a cookie as shown below. Does some information of this need to be posted by the function?

Cookie based on EF entity

Peter le Grand
  • 53
  • 1
  • 1
  • 8
  • 2
    The server side can't access the client side. The client will need to send it up to the server (e.g. using AJAX). – mjwills Aug 04 '20 at 03:02

0 Answers0