asp.net page using the session is stored in ashx

On the page is easy to usual on the request, response to, like, so some of its operations, but in ashx (general processing program) is a little different,

In ashx You can not use the normal session, namely

1 context.session["TestA"]="1111";

Although the generation when it is not being given, but is not assigned, but also to get any value.

To use ashx in the session, you need to reference using System.Web.SessionState; IRequiresSessionState and implement the interface.

using System.Web.SessionState;
public class login : IHttpHandler, IRequiresSessionState {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        string type = context.Request.Form["type"];
        switch (type)
        {
            case "0":
                sendMessage(context);
                break;
            case "1":
                saveUserRealInfo(context);
                break;
        }
}
 /*用户发送短信*/
    private void sendMessage(HttpContext context)
    {
        string mobile = context.Request.Form["mobile"];
        IF (Regex.IsMatch (Mobile, @ "^. 1 [3-9] \ {D} $. 9"))
        {
           Data String = CommClass.Comm.sendMessage // (Mobile,. 1); 
            String Data = "5668"; 
            (! Data = "") IF 
            { 
/ * through the session codes stored, to facilitate verification page * / the Context.Session [Mobile ] = Data; context.Response.Write ( "sent successfully!"); ------------------

  

Guess you like

Origin www.cnblogs.com/fogwang/p/11404913.html