Reputation: 2014
I am trying to call an ashx handler from asp.net page and retrieve xml data from handler.
var url = "http://localhost/Settings/MyHandler.ashx?errors=false";
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
using (var response = (HttpWebResponse)request.GetResponse())
{
using (var stm = response.GetResponseStream())
{
using (var sr = new StreamReader(stm))
{
var data= sr.ReadToEnd();
}
}
}
Now, due to the nature of asp.net creating new session for each webrequest, i am not able to reuse the same session from asp.net page to ashx handler.
Both files are from same project.
How can i reuse the same session from asp.net to ashx handler.?
Please note: i already have marked my handler to implement IRequireSessionState, so it has session. My issue is that aspx page and ashx handler have two different sessions.. Everytime when i invoke handler it creates a new session. But instead i have to reuse the same session of aspx page inside my handler, meaning i have to execute handler in the same request context of my page.
Upvotes: 1
Views: 454
Reputation: 1210
If you specify that your .ashx class uses the IRequiresSessionState interface e.g.
public class myClass : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
}
Then you should be able to get access to the current session values via HttpContext.Current.Session
Upvotes: 1