Question: Cookies created by Javascript not seen by C# (ASP.NET Razor)

Question

Cookies created by Javascript not seen by C# (ASP.NET Razor)

Answers 1
Added at 2017-01-03 15:01
Tags
Question

I'm setting a cookie in Javascript:

document.cookie = "lang=" + lang + ";path=/;domain=" + window.location.hostname + ";";

If I check the cookies in the browser, I can see this one. But when I run :

@if (Response.Cookies.AllKeys.Contains("lang")) {
    @Response.Cookies["lang"].Value;
}

I get no output.

Answers to

Cookies created by Javascript not seen by C# (ASP.NET Razor)

nr: #1 dodano: 2017-01-03 15:01
Response.Cookies 

should be

Request.Cookies

Request.Cookies cookies come from client (browser) to the server and Response.Cookies cookies are sent back to the client (browser) from the server.

Source Show
◀ Wstecz