HttpHandlers and HTTPModules

M

matt

You cannot map a blank extension to be run by asp.net (i.e in your
httpmodule), so the only way I have found to manage this is to create a
custom 404 page which checks if the 404 is caused by the situation you
describe (in its simplest form just checking if the request ends with
..aspx), you can then redirect to the appropriate page using a
Response.Redirect.

As far as I know this really is the only way around this problem,
although I am aware it isn't the most elegant it does solve the problem.

HTH

Matt
 
E

Emad Ibrahim

I need to handle all http requests so that if someone types something like

http://www.mysite.com/123

then I would load the article 123

I can't get this to work because the app keeps looking for a folder called
123 and my custom handlers and modules are not getting called.

Although if I type http://www.mysite.com/123.aspx then my custom handlers
are getting called.

How do I fix this?

Thanks.

- Emad
 
M

Matt Berther

E

Emad Ibrahim

That's not going to work because the page never fires... The problem is
that by calling http://www.mysite.com/123 the code never runs because it is
all trapped in IIS which is looking for a subfolder called 123...

-Emad


Matt Berther said:
Hello Emad,


Look into HttpContext.RewritePath (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html
/frlrfsystemwebhttpcontextclassrewritepathtopic.asp).

"Assigns an internal rewrite path. RewritePath allows for the URL that is
requested to differ from the internal path to the resource. RewritePath is
used in cookieless session state."
 
E

Emad Ibrahim

That doesn't work because the 404 page never runs inside the application.
The 404 page is just a redirect in IIS, which means I can't handle any
events in the page, hence I won't be able to load the articles based on the
URL
 
M

matt

That's not strictly true, if you specify the 404 page in IIS the
requested page is forwarded in the querystring so in your example if
your setup 404.aspx as a redirect URL, the called page will be
404.asp?404;http://www.mysite.com/123. This means that you can then
retrieve the requested url in the 404 page with some code similar to the
following. It does with work because we use it!

string RequestedUrl = Request.QueryString.ToString().Replace("404;);
if(RequestedUrl.EndsWith(".aspx") {
// assume this is a request for a folder...
Response.Redirect(RequestedUrl + ".aspx");
} else {
// assume this is an actual 404 error and do the required
processing;
}

This will ultimately result in a request for http://www.mysite.com/123
being forwarded to http://www.mysite.com/123.aspx

Matt
http://www.3internet.co.uk
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top