IIS 7 returning 404 error with extension less URL

iis7 404 error with extensionless url asp.net 4.0

I was recently working on updated an older asp.net 3.5 website to asp.net 4.0.  Unfortunately we can't upgrade to 4.5 due to the risk of breaking other sites on the same server. Our reason for the upgrade was really to take advantage of the routing ability that was built into asp.net 4.0 for webforms.

If you're looking for help on setting up .net routing you can take a look at a simple 'how to' for setting up routing with WebForms here that I wrote a few years back.

The issue I was having was that IIS was returning a 404 page not found error when I tried to go to a url without the .aspx. I had setup my global.asax file with the correct routing information but it was like IIS was ignoring these rules.

Initially I thought that the server did not have the IIS rewrite module installed or that asp.net was not setup correctly. However the issue was down to my web.config file as it had an old rewrite rule in it to redirect users who came onto our site without a 'www.'. This rewrite rule was making IIS ignoring my global.asax routing table.

The solution was to remove the old redirect rewrite rule:

 

        
            
                
                    
                    
                        
                    
                    
                
            
        
    

and instead just place the following in the system.webserver tag:

    
        
    

This fixed the extension-less 404 error for me. In my next post I will discuss how I put back in my force www redirect rule.

If you are getting a 403 permission denied when you're going to your extension-less pages you might want to take a look at another article I wrote a while back.

C#, IIS7

Share this post


blog comments powered by Disqus

Updates

Follow me online at TwitterFacebook or Flickr. If you want to get in touch with me try emailing me.

Latest Tweets