1

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 trying to set a session 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 {

    public void ProcessRequest (HttpContext context) { 
       string savepath = context.Server.MapPath(tempPath);
       context.Session["AudioFile"] = savepath;

   }  }

Nullreference exception thrown: Object reference not set to an instance of an object.

2 Answers 2

6

Add IRequiresSessionState Interface to your handler definition. Or IReadOnlySessionState, if you only need read-only info, because this can give a minor performance boost by avoiding locking, and writing back session values.

It's just a marker interface that tells the runtime, that this handler needs session state.

public class Upload : IHttpHandler, IRequiresSessionState{
    //...
}
3
  • Now I am able to set session value in handler, but in aspx page the session value is always null, why is it null
    – Murthy
    Jan 30, 2012 at 14:08
  • And session ID in handler is different from the one I get in aspx page. IS that the problem
    – Murthy
    Jan 30, 2012 at 14:15
  • You get different session, and therefore different session ID, if you send a request from different browsers. Or just restart your web server, and request a page, or handler from different tabs. Probably that's your problem. Jan 30, 2012 at 14:56
0

Add Interface IRequiresSessionState to your method like public class Upload : IHttpHandler,IRequiresSessionState {

}

1
  • Could you explain the enhancement over @AkosLukacs 's answer?
    – bummi
    Oct 22, 2014 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.