Custom PageHandlerFactory and Session-Context

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top