1-in ASPX and Aspx.cs, both are session["xxx"]= "AAA" and aaa=session["xxx". ToString () for reading and writing.
In Ashx, the session is to use Context.session, read and write method is this:
Context. session["xxx"]= "AAA" and Aaa=context. session["XXX"]. ToString ()
2-in Ashx file, to read and write the session successfully, you should add the interface IRequiresSessionState after using session class (adding
You may be prompted to add a reference to the namespace using System.Web.SessionState, otherwise the context. session ["XXX"] read out 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 web.ui,ashx can only be passed in the HttpContext instance to request and session and so on operation. Appcode in the CS file no Web.ui, no HttpContext parameters, if the CS can get the current HttpContext, can be based on this HttpContext to operate the request and session.
To operate the session in CS, the IRequiresSessionState interface should be added. The HttpContext class has a static property called Current, which you can use to get the present HttpContext.
In the Appcode CS file to get the current visitor's IP, you can use HttpContext.Current.Request.UserHostAddress.