- Joined
- Mar 31, 2009
- Messages
- 2
- Reaction score
- 0
Hello
I have implemented an IHttpModule that rewrites user-friendly paths to actual file resources. However, since my user-friendly paths have no extensions, such as:
~/mysite/my-friendly-name
...the session object in the context within my PostAcquireRequestState event handler is empty. This is not a problem; I simply assign a dummy handler to my request in a PostMapRequestHandler event handler, like this:
if (contentPage != null && handler.GetType() == typeof(System.Web.DefaultHttpHandler))
HttpContext.Current.Handler = new EnforceSessionStateHandler();
Where EnforceSessionStateHandler looks like this:
public class EnforceSessionStateHandler : IHttpHandler, IRequiresSessionState
{
public bool IsReusable
{
get { throw new NotImplementedException(); }
}
public void ProcessRequest( HttpContext context )
{
throw new NotImplementedException();
}
}
It is within my PostAcquireRequestState method handler that I am actually doing the rewrite. Previously, I have been using Server.Transfer() to do the rewrite, which worked fine until I started adding user controls to the page. Then I discovered that the post back data was being lost because of the transfer - none of the events of my controls were being raised (such as an OnClick for a button).
So, I changed the Server.Transfer() to a HttpContext.RewritePath(). However, this invokes the ProcessRequest90 method of my dummy EnforceSessionStateHandler handler, which of course throws an exception.
So I think I have three choices:
1) I find a means to acquire the state in the PostAcquireRequestState and use HttpContext.RewritePath() without having to create a dummy handler;
2) or, I somehow dynamically create the page using the Activator class - unfortunately the page's class is not available via reflection because it's not being compiled into an assembly during debugging;
3) or, I take the post back state from the request object and somehow inject this into my Server.Transfer().
Does anyone have any ideas how I could proceed with this?
Regards, Mark
I have implemented an IHttpModule that rewrites user-friendly paths to actual file resources. However, since my user-friendly paths have no extensions, such as:
~/mysite/my-friendly-name
...the session object in the context within my PostAcquireRequestState event handler is empty. This is not a problem; I simply assign a dummy handler to my request in a PostMapRequestHandler event handler, like this:
if (contentPage != null && handler.GetType() == typeof(System.Web.DefaultHttpHandler))
HttpContext.Current.Handler = new EnforceSessionStateHandler();
Where EnforceSessionStateHandler looks like this:
public class EnforceSessionStateHandler : IHttpHandler, IRequiresSessionState
{
public bool IsReusable
{
get { throw new NotImplementedException(); }
}
public void ProcessRequest( HttpContext context )
{
throw new NotImplementedException();
}
}
It is within my PostAcquireRequestState method handler that I am actually doing the rewrite. Previously, I have been using Server.Transfer() to do the rewrite, which worked fine until I started adding user controls to the page. Then I discovered that the post back data was being lost because of the transfer - none of the events of my controls were being raised (such as an OnClick for a button).
So, I changed the Server.Transfer() to a HttpContext.RewritePath(). However, this invokes the ProcessRequest90 method of my dummy EnforceSessionStateHandler handler, which of course throws an exception.
So I think I have three choices:
1) I find a means to acquire the state in the PostAcquireRequestState and use HttpContext.RewritePath() without having to create a dummy handler;
2) or, I somehow dynamically create the page using the Activator class - unfortunately the page's class is not available via reflection because it's not being compiled into an assembly during debugging;
3) or, I take the post back state from the request object and somehow inject this into my Server.Transfer().
Does anyone have any ideas how I could proceed with this?
Regards, Mark