简体   繁体   中英

How can I get the session value in code behind from handler page

I am using uploadify to upload a audio file. It uses the handler upload.ashx to upload the file to the server. I want to get the file path in my aspx page. So I am set a session value in handler so that I get the file path in aspx but I am not able to do so. How can I get the value of file path from handler to .aspx page

   public class Upload : IHttpHandler,IRequiresSessionState        {   
    public void ProcessRequest (HttpContext context)         {        
    string savepath = context.Server.MapPath(tempPath);     
    context.Session["VideoFile"] = savepath;     }  } 

In my aspx page when I try to get the file path

      DocLink = Session["VideoFile"].ToString();

the session value is always null. How can I get the session value in code behind

 string path= HttpContext.Current.Request.Cookies["VideoFile"].ToString();

I tried this, even this is null

If you call it with the context like context.Session["VideoFIle"] and everything is ok, then the second possible reason is that you do not have setup correct the path on the cookies properties.

Check and set the domain on the httpCookies on web.config to be sure that is with out the www. and be able to read it from any page started on your domain

<httpCookies domain="domain.com" httpOnlyCookies="false" requireSSL="false" />

Why is that, because if you do not set the domain on cookies then the cookie is writed with the domain that its read from the url, and the session is connected to the cookie. If your domain change, eg you call it with www.domain.com , and in one page call you use domain.com then the cookie is not the same, and the session is not the same.

Note

Inside your handler the context is comming from the parametre that calling the ProcessRequest and not from HttpContext.Current.Request . Maybe this is one more issue on your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM