That is a really interesting question! Did anybody find a solution of how to access the Session variables inside a HttpHandlerFactory?
I tried now multiple things and the least worse one, which still does not work is this one, I think:
public IHttpHandler GetHandler(HttpContext context,
string requestType,
string url, string pathTranslated)
{
string newUrl = url;
Match match =
this.regex.Match(url);
if (match.Success)
newUrl = this.siteRegex.Replace(url,
"/");
IHttpHandler handler =
PageParser.GetCompiledPageInstance(newUrl, context.Server.MapPath(newUrl), context);
if (match.Success)
{
if (handler
is MyPage)
{
HttpSessionState session = (handler
as MyPage).Session;
session["VALUE"] = match.Value;
}
}
return handler;
}
context.Session is still null, HttpContext.Session is null and if I try to access the Session from the handler I get an exception that the session state can only be used if enableSessionState is set to true and so forth.
MyPage implements IRequiresSessionState, the property EnableSessionState is set to true and I do use the session inside the page_load and so on. I just cannot access it from the HttpHandlerFactory.
Purpose of that factory is to extract a value from the url, redirect the user to the correct page and set some values othe session that I use to fetch data, but that should not be setable via the querystring.
John.Doe
Member
430 Points
176 Posts
Re: HTTP Handler factory: the HttpContext argument is not initialized?
Sep 20, 2006 06:54 PM|LINK
That is a really interesting question! Did anybody find a solution of how to access the Session variables inside a HttpHandlerFactory?
I tried now multiple things and the least worse one, which still does not work is this one, I think:
public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
{
string newUrl = url;
Match match = this.regex.Match(url);
if (match.Success)
newUrl = this.siteRegex.Replace(url, "/");
IHttpHandler handler = PageParser.GetCompiledPageInstance(newUrl, context.Server.MapPath(newUrl), context);
if (match.Success)
{
if (handler is MyPage)
{
HttpSessionState session = (handler as MyPage).Session;
session["VALUE"] = match.Value;
}
}
return handler;
}
context.Session is still null, HttpContext.Session is null and if I try to access the Session from the handler I get an exception that the session state can only be used if enableSessionState is set to true and so forth.
MyPage implements IRequiresSessionState, the property EnableSessionState is set to true and I do use the session inside the page_load and so on. I just cannot access it from the HttpHandlerFactory.
Purpose of that factory is to extract a value from the url, redirect the user to the correct page and set some values othe session that I use to fetch data, but that should not be setable via the querystring.