您的位置:首页 > 编程语言 > ASP

asp.net设置默认打开页面 Web.config defaultDocument

2013-04-19 15:38 411 查看
Web.config defaultDocument

The web.config file can be used to set a default document, or list of default documents for your website. Web.config can be used to change the default document (page) for an entire site, or on a directory by directory basis. The default page may be a .php,
.asp, .htm, .aspx, .cfm, or any other file type handled by the web server.

While some web.config sections require that the containing directory is set as an application, this isn't one of them. A simple web.config with a defaultDocument section may be placed in any directory, and the directory does NOT need to be set as an application.

Purpose

The default document is returned to the client when the browser requests a directory name (foo.com/, foo.com/somedir/), but doesn't specify
a page. If there isn't a default document in the directory, the client will receive a "file not found" or "directory browsing denied" error. The web server is configured to search for default files in the order listed below. If you wish to chage the default
document order or add another file name, please follow the directions on this page.

index.htm
index.html
default.asp
default.aspx
index.asp
index.aspx
index.cfm
index.php
default.htm

How it's done

Example default document list. Comments are enclosed in <!--
--> and are not required.

Clear all default documents, then add a list of documents
<defaultDocument enabled="true">    <!-- this line enables default documents for a directory -->
<files>
<clear/>     <!-- removes the existing default document list -->
<add value="foo.htm"/>     <!-- foo.htm is now the default document  -->
<add value="foo.php"/>     <!-- 2nd default document in search order -->
<add value="foo.aspx/>     <!-- 3rd default document in search order -->
<add value="foo.cfm/>      <!-- 4th default document in search order -->
</files>
</defaultDocument>


Using Custom Default Documents

Use a text editor to create a file named web.config
Save the web.config file with the appropriate content
Place the web.config file in the directory that you wish to modify

Detailed web.config content

If there isn't an existing web.config in the directory, your new web.config should look something like this
<?xml version="1.0"?>
<configuration>
<system.webServer>
<defaultDocument enabled="true"> <!-- this line enables default documents for a directory --> <files> <clear/> <!-- removes the existing default document list --> <add value="foo.htm"/> <!-- foo.htm is now the default document --> <add value="foo.php"/> <!-- 2nd default document in search order --> <add value="foo.aspx/> <!-- 3rd default document in search order --> <add value="foo.cfm/> <!-- 4th default document in search order --> </files> </defaultDocument><modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>


If there is an existing web config, without a <system.webServer> section... Your new web.config should look like this
<?xml version="1.0"?>
<configuration>
<system.web>
.. existing text ..
.. existing text ..
</system.web>
<system.webServer>
<defaultDocument enabled="true"> <!-- this line enables default documents for a directory --> <files> <clear/> <!-- removes the existing default document list --> <add value="foo.htm"/> <!-- foo.htm is now the default document --> <add value="foo.php"/> <!-- 2nd default document in search order --> <add value="foo.aspx/> <!-- 3rd default document in search order --> <add value="foo.cfm/> <!-- 4th default document in search order --> </files> </defaultDocument><modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>


If your existing web.config already has a <system.webServer> section, just add the <defaultDocument> section
<?xml version="1.0"?>
<configuration>
<system.web>
.. existing text ..
.. existing text ..
</system.web>
<system.webServer>
<defaultDocument enabled="true"> <!-- this line enables default documents for a directory --> <files> <clear/> <!-- removes the existing default document list --> <add value="foo.htm"/> <!-- foo.htm is now the default document --> <add value="foo.php"/> <!-- 2nd default document in search order --> <add value="foo.aspx/> <!-- 3rd default document in search order --> <add value="foo.cfm/> <!-- 4th default document in search order --> </files> </defaultDocument><modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐