We help IT Professionals succeed at work.

Create virtual directory through global.asax without using iis

Bakersville
Bakersville used Ask the Experts™
on
Hi all

I code in vb.net

Currently i have used a Application_BeginRequest to change my criterial based url into something easier for the user to see and type in my global.asax page which uses httpContext.RewritePath. ie, www.domain.com/contactus.aspx points to www.domain.com/pagename.aspx?id=123

However, i am now wanting to make virtual directories, ie, www.domain.com/contactus/ but point it to www.domain.com/pagename.aspx?id=123 using the same httpContext.RewritePath.

I have changed the code to allow to search the database for anything with or without a .aspx, but everythime i key in www.domain.com/contactus/ it comes up with a "page cannot be displayed error"

I know you can use web.config to do the rewrites, however, as it uses a database, could not get it to work.

I hope this explains everything and any help would be very much appriciated.

Baker
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2014

Commented:
I think anything none aspx/ascx/asmx/... is handled by IIS without involving ASP.NET so your begin request is never called. I think this behaviour has changed with either a recent version of IIS or ASP.NET but not sure about that.

Author

Commented:
Thank you CodeCruiser

Is there anyway to get iis to look for a .aspx page whenever a request is made throughout the entire site?

Baker
Most Valuable Expert 2012
Top Expert 2014
Commented:
No. You can write an HTTP handler and register it with IIS so it processes all the requests (you can do url rewriting in it)

Approach 2

http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

Author

Commented:
Thank you, this works.

Might just go to IIS 7 though as it looks like a lot easier than 6