Session variable become null asp.net




















Manas Bhardwaj 5-Nov pm. Add your solution here. OK Paste as. Treat my content as plain text, not as HTML. Existing Members Sign in to your account. This email is in use. Do you need your password? Submit your solution! When answering a question please: Read the question carefully.

Understand that English isn't everyone's first language so be lenient of bad spelling and grammar. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem.

Insults are not welcome. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid. Related Questions. Loosing Session variable value on Response. AddDistributedMemoryCache ; services. Session"; options. UseSession ; app. Any help will be highly appreciated!

Improve this question. TanvirArjel TanvirArjel Add a comment. Active Oldest Votes. For ASP. NET Core 2. Improve this answer. Works for me in asp. Great Thanks — PatsonLeaner. This worked for me. Thank you. Some others suggested adding services. AddMemoryCache to ConfigureServices and app.

UseCookiePolicy to Configure, but that wasn't necessary. But doesn't this indicate CheckConsentNeeded is false by default? As a boolean property default value is false but during the project template generation default value is set to true.

Not Working for me. Is there anything else which i can do. Session is not available on the page constructor! Only on the Init event or after that. I just encountered an HttpContext.

Apparently, this can occur in the context of a page. If I inspect the HttpContext. Whatever the cause, this issue has not occurred in production, where it has run for years. Net 3. I have also found that, when IIS is serving a direct request for a resource file which exists on disk, such as a style sheet, HttpContext. The request for the page itself, however, does make the session object available to code there.

This is under MVC. NET 4 at least. I think it could also be null if you are inside an output-cached MVC action. The following statement is not entirely accurate: "So if you are calling other functionality, including static classes, from your page, you should be fine" I am calling a static method that references the session through HttpContext.

Thanks to Matthew Cosier for the solution. Just thought I'd add my two cents. Ed Bishop Ed Bishop 8 8 silver badges 18 18 bronze badges. Well, when you are calling into a webservice, you use another request than for the page, so that statement is still correct, IMO. MSDN docs here - the default value is false. Works like a charm. Thank you very much, session was null in my login class. I think this answers the question quite well. Thanks so much. Sign up or log in Sign up using Google. Sign up using Facebook.

Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually.

Linked 0. See more linked questions. Related 1. Hot Network Questions.



0コメント

  • 1000 / 1000