D
Daniel Meier
Hi
I'm using a custom PageHandlerFactory as it's used in Microsofts p&p
WebClient Software Factory.
The problem is, that I cannot use Sessions now;
HttpContext.Current.Session is null.
When I use the standard PageHandlerFactory instead, all works fine.
What do I have to do, to enable SessionState with my custom
PageHandlerFactory?
Here's my PageHandlerFactory-class:
public class CustomPageHandlerFactory : PageHandlerFactory,
IRequiresSessionState
{
const string _appSettingKey = "ClientIdMapperEnabled";
public override System.Web.IHttpHandler
GetHandler(System.Web.HttpContext context, string requestType, string
virtualPath, string path)
{
Page page = (Page) base.GetHandler(context, requestType,
virtualPath, path);
page.Init += new System.EventHandler(page_PreInit);
PresentationFactory factory = new PresentationFactory();
factory.InitializeView(page);
SessionStateUtility.AddHttpSessionStateToContext(context);
return page;
}
void page_PreInit(object sender, EventArgs e)
{
RenderControlIdMap((Page)sender, HttpContext.Current);
}
private void RenderControlIdMap(Page page, HttpContext context)
{
string mapperEnabledSetting =
ConfigurationManager.AppSettings[_appSettingKey];
bool addMapper = false;
if (!String.IsNullOrEmpty(mapperEnabledSetting) &&
Boolean.TryParse(mapperEnabledSetting, out addMapper))
{
if (addMapper)
{
page.Controls.Add(new ClientIdMapper());
}
}
}
}
Thank you
Daniel
I'm using a custom PageHandlerFactory as it's used in Microsofts p&p
WebClient Software Factory.
The problem is, that I cannot use Sessions now;
HttpContext.Current.Session is null.
When I use the standard PageHandlerFactory instead, all works fine.
What do I have to do, to enable SessionState with my custom
PageHandlerFactory?
Here's my PageHandlerFactory-class:
public class CustomPageHandlerFactory : PageHandlerFactory,
IRequiresSessionState
{
const string _appSettingKey = "ClientIdMapperEnabled";
public override System.Web.IHttpHandler
GetHandler(System.Web.HttpContext context, string requestType, string
virtualPath, string path)
{
Page page = (Page) base.GetHandler(context, requestType,
virtualPath, path);
page.Init += new System.EventHandler(page_PreInit);
PresentationFactory factory = new PresentationFactory();
factory.InitializeView(page);
SessionStateUtility.AddHttpSessionStateToContext(context);
return page;
}
void page_PreInit(object sender, EventArgs e)
{
RenderControlIdMap((Page)sender, HttpContext.Current);
}
private void RenderControlIdMap(Page page, HttpContext context)
{
string mapperEnabledSetting =
ConfigurationManager.AppSettings[_appSettingKey];
bool addMapper = false;
if (!String.IsNullOrEmpty(mapperEnabledSetting) &&
Boolean.TryParse(mapperEnabledSetting, out addMapper))
{
if (addMapper)
{
page.Controls.Add(new ClientIdMapper());
}
}
}
}
Thank you
Daniel