开发者

Extensionless Page Requests

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 introduc开发者_JS百科e code if possible.


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.


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....


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜