0

I am trying to access the session values in .CS file but getting the following error:

'HttpContext' does not contain definition for 'Current'

This is my code:

form.aspx.cs

Session["from"] = lblMgrMailFrom.Text;

class.cs located in a .NET Standard library

string from = System.Web.HttpContext.Current.Session["from"];
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • If you have access to a debugger, perhaps you could set a breakpoint and inspect the HttpContext to see what it does/doesn't contain. That information may be helpful to you. – trademark Feb 26 '20 at 15:05
  • @trademark That is a compiler error, so debugging should not be possible. – D Stanley Feb 26 '20 at 15:06
  • 1
    Are you using .net core perhaps? – Igor Feb 26 '20 at 15:07
  • @Igor If it was .NET Core, they probably would not be on a page called form.aspx.cs, which is for Web Forms. – mason Feb 26 '20 at 15:08
  • no i am not using .net core – Banala Amarnath Feb 26 '20 at 15:10
  • 1
    We need more information here to be able to help you. Please be explicit about the framework you're using (Web Forms, ASP.NET etc) and describe where class.cs is. Is it in the same project as your web application, or a separate class library? Is it .NET Standard or .NET Framework etc? – mason Feb 26 '20 at 15:10
  • @mason - I have seen users copy and paste code files from online into their projects hoping they would just work and then post the errors on [so]. You never know... – Igor Feb 26 '20 at 15:14
  • 1
    @DStanley At the very least you can just do `var foo = System.Web.HttpContext;` and then it will compile so you can debug and inspect. – trademark Feb 26 '20 at 15:17
  • its asp.net,and it is a .net Standard – Banala Amarnath Feb 26 '20 at 15:20
  • 1
    Why did you make it a .NET Standard library? If you have no particular reason, then perhaps you should convert it to a .NET Framework class library. Or just don't consume HttpContext from your .NET Standard library. – mason Feb 26 '20 at 15:23
  • Duplicate of [HttpContext in .net standard library](https://stackoverflow.com/q/47357689/1260204) – Igor Feb 26 '20 at 15:43

0 Answers0