Non-Existent folder urlrewrite without changing ISAPI

  • Thread starter Thread starter dkode
  • Start date Start date
D

dkode

Hello,

The webhost that I have my asp.net website with does not allow me to
change the ISAPI handler for IIS, I am wondering if there is a way to
accomplish this without modifying the ISAPI handler.

a user goes to: http://www.mysite.com/username/

and it redirects to:

http://www.mysite.com/default.aspx?u=username

Now, I see you can do this with an HttpModule, but because of the fact
that the folder /username/ doesnt exist, IIS will throw a 404 error.

Is there anyway around this since I can't modify or add my own ISAPI
handler?
 
HttpContext.RewritePath(string filePath, string pathInfo, string
queryString).

I call it in Application_BeginRequest (Global.asax.cs), and then in the
page load (default.aspx) write it back to the requested url. The code
is something like:

1) if the requested file is an ".axd" (resource handler request, such
as for freetextbox) then return without rewrite
2) check if requested physical page exists on the server, and if so
return without rewrite (to allow hardcoded pages to be accessible)
3) process the requested url and see if you know what it means. In
your case check the last folder name, look the user up, if they do not
exist, return without rewrite so a 404 error occurs. If they do exist,
call rewrite path with your new url.
4) you really should write the url back to the original in the page
load if you expect that page to post back to the server. Otherwise
when they post back they will not see your hackable (friendly) url in
the address bar anymore, but instead see your rewritten url.

This resource may help:
http://odetocode.com/blogs/scott/archive/0001/01/01/509.aspx

You can look at my site to see the friendly urls in use. None of the
following pages physically exist on the server. They are all really
just default.aspx, which you can also access directly:
http://www.xquisoft.com/Products/VersionPolicy.aspx
http://www.xquisoft.com/Products/Portal/Overview.aspx
http://www.xquisoft.com/Products/Portal/Progress.aspx
http://www.xquisoft.com/home.aspx

are all really just...
http://www.xquisoft.com/default.aspx

Michael Lang
XQuiSoft LLC
(XQuiSoft Portal Framework)
http://www.xquisoft.com/
 
excellent!

I thought there was a way to do this without changing the ISAPI
handler. I cringe at the thought :)

Now, one more question.

This is one of first asp.net 2.0 apps, up to this point they were all
v1.1

I noticed in asp.net 2.0 there is no global.asax.cs, how do i add this
functionality to the Authenticate_Request with no Global.asax?

thanks alot!

Sean
 
actually the odetocode link you gave me earlier has a link to C# 2005
code, which explains it in framework 2.0.

the previous example is not very scalable as they have all the entries
hard coded into the web.config.

I beleieve the original solution would be perfect! thanks

sean
 
Back
Top