asp.net设置默认打开页面 Web.config defaultDocument
2014-06-23 17:38
441 查看
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
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
If there is an existing web config, without a <system.webServer> section... Your new web.config should look like this
If your existing web.config already has a <system.webServer> section, just add the <defaultDocument> section
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>
相关文章推荐
- asp.net设置默认打开页面,Web.config,defaultDocument
- asp.net设置默认打开页面 Web.config defaultDocument
- asp.net通过web.config设置网站默认页
- asp.net中web.config设置默认首页
- 页面中设置默认的回车激活按钮, ASP.NET DefaultButton 属性
- ASP.NET程序中动态修改web.config中的设置项目(前台页面代码)
- 设置页面的默认焦点控件和默认接受事件控件How Do I Set the DefaultFocus or DefaultButton in a Page Based on a Master Page in ASP.NET 2.0
- 在web.config设置asp.net 页面缓存
- 打开ASP.NET Web项目时,此项目的默认Web访问模式设置为文件共享, 但是无法从路径“...”打开“...”处的项目文件夹。返回的错误是: 无法打开Web项目“”。返回的错误是: 无法打开Web项目“...”。文件路径“...”怀URL“...”不
- 打开ASP.NET Web项目时,此项目的默认Web访问模式设置为文件共享, 但是无法从路径“...”打开“...”处的项目文件夹。返回的错误是: 无法打开Web项目“”。返回的错误是: 无法打开Web项目“...”。文件路径“...”怀URL“...”不
- 在web.config设置asp.net 页面缓存
- ASP.NET中动态修改web.config中的设置项目(CS页代码)(转贴)
- asp.net设置页面默认按钮
- ASP.NET中动态修改web.config中的设置项目(CS页代码)
- ASP.NET 2.0 web.config数据库连接设置与读取
- 设置asp.net程序在web.config被修改后是否重启
- ASP.NET中动态修改web.config中的设置项目(前台代码)
- asp.net 2.0中新增的web.config的默认namespace功能
- ASP.NET中动态修改web.config中的设置项目(前台代码)
- ASP.NET 2.0 web.config数据库连接设置与读取