Search code examples
c#asp.net-routing

Url routing problem with IIS7


Url routing and IIS7 03-24-2011 04:24 PM

Hi,

I have a query regarding Url Routing in asp.net 4.0 and IIS7. Below I have explained what is my website structure and how it is configured in IIS7.

Directory Structure:

1.MyWebsite>Index.aspx

2.MyWebsite>AboutUs>Index.aspx

3.MyWebsite>ContactUs>ContactUs.aspx

II7 Configuration:

I have configured my application's default document as Index.aspx Now, when i access below urls, IIS7 does few routing automatically (note that until now i havent added any routes in global.asax )

1.localhost/MyWebsite will be forwarded to localhost/MyWebsite/Index.aspx Ok !!

2.localhost/MyWebsite/Aboutus will be forwarded to localhost/AboutUs/Index.aspx (this redirection is done as parent level default document is inherited by AboutUs folder) Ok !!

3.localhost/MyWebsite/ContactUs == Http Error 403.14 Forbidden (This error is thrown by IIS7 becoz it doesnt find Index.aspx in Conactus folder) Fine !!

Ok so for localhost/MyWebsite/ContactUs to be routed to localhost/MyWebsite/ContactUs/Index.aspx I added below code in RegisterRoutes() method in global.asax hoping this will fulfill my requirement.

routes.MapPageRoute('ConactUs','ContactUs','~/ContactUs/ContactUs.aspx');

So now when i acces localhost/MyWebsite/ContactUs i still get the same Forbidden error. So is IIS7 default page setting at root not allowing my routes to work?

If I have Index.aspx page in each folder then it works i.e.redirection to /Contactus/Index.aspx ... but what if i dont have Index.aspx (my default document) in every page?

Thanks & Kind regards, m .


Solution

  • Ok here is what i did to work things for me. First of all let me again add few more details about my project..

    Directory Structure:

    1.MyWebsite>Index.aspx

    2.MyWebsite>AboutUs>Index.aspx

    3.MyWebsite>ContactUs>ContactUs.aspx

    All my pages have a UserControl named logo.ascx. logo.ascx doesnt have a code behind file attached to it. It just have a html with resolve.clienturl() method. And logo.ascx just have below attribute; <%@ Control Language="C#" %>

    So to make every thing working i did a couple of things,

    1. For every directory i selected different Default Document as per my need. so whenever a directory is browsed i will automatically be routed to my selected default page.
    2. I added route in global.asax files for non directory browsing.
    3. I made RouteExistingFiles= true;
    4. Then I made sure that whatever route i added , i replaced all the direct links to that page to short url. like I replaced localhost/MyWebsite/ContactUs/ContactUs.aspx with localhost/MyWebsite/ContactUs throughout my project (like in menus, sub menus etc.).
    5. But doing all this had a weird problem, i wasnt able to see my logo image. I was sure that i had used resolve.cienturl() and it was working fine in all my non routing pages. But only for pages that had their route added image wasnt visible. To make this working all i had to do was just add a code behind file to my logo.ascx and magic it worked.

    Thanks naraen thanks pauli for ur support and suggestions.