1-in ASPX and Aspx.cs, both are session["xxx"]= "AAA" and aaa=session["xxx"]. ToString () to read and write.
In Ashx, the Session uses context.session, and the reading and writing methods are:
Context. session["xxx"]= "AAA" and Aaa=context. session["XXX"]. ToString ()
2-In the Ashx file, to successfully read and write to the session, you should add the interface IRequiresSessionState after using the session class (adding
You may be prompted to add a namespace using the System.Web.SessionState reference) otherwise context. Session ["xxx"] read out is always null
Aspx.cs is the direct request and session, while in the ASHX is the context. Request and context. Session.aspx.cs can be used directly, because there are only web.ui,ashx in the HttpContext instance of the request and session to operate. Appcode in the CS file does not have Web.ui, there is no HttpContext parameter, if CS can get the current HttpContext, you can according to this HttpContext to operate the request and session.
To operate the session in CS, the IRequiresSessionState interface should be added. There is a static property called current in the HttpContext class, which can be used to get the present HttpContext.
In the Appcode CS file to get the current visitor's IP, you can use HttpContext.Current.Request.UserHostAddress.
How to get session in ASP. NET Ashx