views:

48

answers:

3

I have a customer of ours that sent out a publication referring to my site but they used the wrong address...they did not provide a page name...it looks like this:

mywebsite.org/Resources/toolkits/bridging

when it should have been

mywebsite.org/Resources/toolkits/bridging/default.aspx

Is there a way to tell ASP.NET to default to this default.aspx when it sees this kind of request or even better, have IIS 7 handle this easily? This site is live so I would like to avoid having to introduce code if possible.

+4  A: 

In the Documents tab of the web site properties in IIS you can specify default documents. If you are using .Net2.0 or later on that machine then Default.aspx should already be set....

ck
+4  A: 

Default.aspx is not, oddly enough, set as the default document in an IIS installation; In IIS 7, the setting is under "HTTP Features", called "Default Document". Add default.aspx to that list and you should be OK.

If not, you'll need to add a 404 handler that redirects when it sees that URL.

Aric TenEyck
+5  A: 

As per other suggestions, this should be done in the IIS configuration for your website using the IIS Admin tool.

There is however, another alternative - you can add a section in the web.config of your actual ASP.NET application, allowing you to override the IIS configuration right from your application:

<system.webServer>
    <defaultDocument>
        <files>
            <clear />
            <!-- Specify each of your files by order of preference here -->
            <add value="Default.aspx" />
            <add value="Index.aspx" />
            <add value="MyOtherPage.aspx" />
        </files>
    </defaultDocument>
</system.webServer>

The caveat to this though is it may be a little obtuse when the IIS administrator can't figure out why the server configuration isn't working the way he's got it configured. It's not always right to do something just because you can.

Finally, just in case you don't have access to the IIS server or your IIS administrator has reasons for not adding Default.aspx to the default document list in the IIS configuration and for whatever reason, you don't wish to override the IIS configuration in your web.config file, then the quickest and simplest way is to simply create a file called default.asp in that directory containing:

<% Response.Redirect("default.aspx") %>

Default.asp is in the default document list on IIS. The code will automatically redirect the call to the correct page. The downside to this approach though is that there's a performance hit - every time someone calls default.asp - directly or otherwise, the redirect needs to happen which isn't free.

BenAlabaster
Ben, for what it's worth, I think you're wrong about the caveat there. IMO, your solution here is *spot-on*, no caveat required. This type of thing should be in the configuration for the application ... exactly what you put forth.
Chris Simmons
I'm inclined to think though that this doesn't necessarily follow the principle of least surprise for the IIS administrator. I agree that this is something that should be specific to the application though, not the web server. So maybe this *shouldn't* be set (nor be available to be set) in the web server? Just throwing that out there as a side note I suppose...
BobTheBuilder