Problem with URL rewriting in IHttpModule

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
 
Joined
Mar 31, 2009
Messages
2
Reaction score
0
Temporary solution...

Ok,

FYI, I think I've found a problem, but I'm not entirely happy with it. I think it's rather slow. I decided on option 2 above, like this: if (contentPage != null && handler.GetType() == typeof(System.Web.DefaultHttpHandler))
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();

bool exitFor = false;

foreach (Assembly assembly in assemblies)
{
Type[] types = assembly.GetTypes();

foreach (Type type in types)
{
if (type.Name == "content_aspx")
{
HttpContext.Current.Handler = (IHttpHandler)Activator.CreateInstance(type);
exitFor = true;
break;
}
}

if (exitFor) break;
}
}

Does anyone have any idea how I can improve this?

Thanks, Mark
 

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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top