Asp.Net 之 Web.config 配置文件详解 -转

在asp.net中配置文件名一般默认是web.config。每个web.config文件都是基于XML的文本文件,并且可以保存到Web应用程序中的任何目录中。在发布Web应用程序时web.config文件并不编译进dll文件中。如果将来客户端发生了变化,仅仅需要用记事本打开web.config文件编辑相关设置就可以重新正常使用,非常方便。

1、配置文件的查找优先级

[1]在.net提供了一个针对当前机器的配置文件,这个文件是machine.config,它位于%windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG\文件下(%windir%是系统分区下的系统目录,在命令行模式下输入%windir%然后回车就能查看当前机器的系统目录,在Windows7及Windows10中%windir%是系统分区下的windows目录,这个文件里面定义了针对当前机器的WinForm程序和asp.net应用程序的配置。下面是machine.config文件的内容:
  machine.comfig

[2]在这个文件夹下还有一个web.config文件,这个文件包含了asp.net网站的常用配置。下面是这个web.config文件的内容:

  View Code

[3]asp.net网站IIS启动的时候会加载配置文件中的配置信息,然后缓存这些信息,这样就不必每次去读取配置信息。在运行过程中asp.net应用程序会监视配置文件的变化情况,一旦编辑了这些配置信息,就会重新读取这些配置信息并缓存。

[4]当我们要读取某个节点或者节点组信息时,是按照如下方式搜索的:
    (1)如果在当前页面所在目录下存在web.config文件,查看是否存在所要查找的结点名称,如果存在返回结果并停止查找。
    (2)如果当前页面所在目录下不存在web.config文件或者web.config文件中不存在该结点名,则查找它的上级目录,直到网站的根目录。
    (3)如果网站根目录下不存在web.config文件或者web.config文件中不存在该节点名则在%windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config文件中查找。
    (4)如果在%windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config文件中不存在相应结点,则在%windir%\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config文件中查找。
    (5)如果仍然没有找到则返回null。

  所以如果我们对某个网站或者某个文件夹有特定要求的配置,可以在相应的文件夹下创建一个web.config文件,覆盖掉上级文件夹中的web.config文件中的同名配置即可。这些配置信息的寻找只查找一次,以后便被缓存起来供后来的调用。在asp.net应用程序运行过程中,如果web.config文件发生更改就会导致相应的应用程序重新启动,这时存储在服务器内存中的用户会话信息就会丢失(如存储在内存中的Session)。一些软件(如杀毒软件)每次完成对web.config的访问时就会修改web.config的访问时间属性,也会导致asp.net应用程序的重启。

 

2、配置文件节点说明

  web.config文件是一个XML文件,它的根结点是<configuration>,在<configuration>节点下的常见子节点有:<configSections>、<appSettings>、<connectionStrings>和<system.web>。     其中<appSettings>节点主要用于配置一些网站的应用配置信息,而<connectionStrings>节点主要用于配置网站的数据库连接字符串信息。
<system.web>节点主要是网站运行时的一些配置,它的常见节点有如下:

[1]<appSettings>节点
  <appSettings>节点主要用来存储asp.net应用程序的一些配置信息,比如上传文件的保存路径等,以下是一个例子:

<appSettings> 
    <!--允许上传的图片格式类型--> 
    <add key="ImageType" value=".jpg;.bmp;.gif;.png;.jpeg"/> 
    <!--允许上传的文件类型--> 
    <add key="FileType" value=".jpg;.bmp;.gif;.png;.jpeg;.pdf;.zip;.rar;.xls;.doc"/> 
</appSettings>

  对于<appSettings>节点中的值可以按照key来进行访问,以下就是C#一个读取key值为“FileType”节点值的例子:

string fileType=ConfigurationManager.AppSettings["FileType "];

[2]<connectionStrings>节点
  <connectionStrings>节点主要用于配置数据库连接的,我们可以<connectionStrings>节点中增加任意个节点来保存数据库连接字符串,将来在代码中通过代码的方式动态获取节点的值来实例化数据库连接对象,这样一旦部署的时候数据库连接信息发生变化我们仅需要更改此处的配置即可,而不必因为数据库连接信息的变化而需要改动程序代码和重新部署。
    以下就是一个<connectionStrings>节点配置的例子:

<connectionStrings> 
    <!--SQL Server数据库配置--> 
    <add name="AspNetStudyConnectionString1" connectionString="Data Source=(local);Initial Catalog=AspNetStudy;User ID=sa;Password=sa"/> 
</connectionStrings>

  在代码中我们可以这么实例化数据库连接对象:

//读取web.config节点配置    
string connectionString = ConfigurationManager.ConnectionStrings["AspNetStudyConnectionString1"].ConnectionString; 
//实例化SqlConnection对象    
SqlConnection connection = new SqlConnection(connectionString);

  这样做的好处是一旦开发时所用的数据库和部署时的数据库不一致,仅仅需要用记事本之类的文本编辑工具编辑connectionString属性的值就行了。

[2]<compilation>节点
  <compilation>节点配置 ASP.NET 使用的所有编译设置。默认的debug属性为“true”,即允许调试,在这种情况下会影响网站的性能,所以在程序编译完成交付使用之后应将其设为“false”。

    <compilation debug="true">
        ......
    </compilation>

[4]<authentication>节点设置asp.net身份验证模式,有四种身份验证模式,它们的值分别如下:
Mode 验证模式说明
1)Windows 使用Windows身份验证,适用于域用户或者局域网用户。
2)Forms 使用表单验证,依靠网站开发人员进行身份验证。
3)Passport 使用微软提供的身份验证服务进行身份验证。
4)None 不进行任何身份验证。
<authentication>节点控制用户对网站、目录或者单独页的访问,必须配合<authentication>节点一起使用。

[5]<customErrors>节点
  <customErrors>节点用于定义一些自定义错误信息的信息。此节点有Mode和defaultRedirect两个属性,其中defaultRedirect属性是一个可选属性,表示应用程序发生错误时重定向到的默认URL,如果没有指定该属性则显示一般性错误。Mode属性是一个必选属性,它有三个可能值,它们所代表的意义分别如下:
Mode值说明
1)On 表示在本地和远程用户都会看到自定义错误信息。
2)Off 禁用自定义错误信息,本地和远程用户都会看到详细的错误信息。
3)RemoteOnly 表示本地用户将看到详细错误信息,而远程用户将会看到自定义错误信息。
  这里有必要说明一下本地用户和远程用户的概念。当我们访问asp.net应用程时所使用的机器和发布asp.net应用程序所使用的机器为同一台机器时成为本地用户,反之则称之为远程用户。在开发调试阶段为了便于查找错误Mode属性建议设置为Off,而在部署阶段应将Mode属性设置为On或者RemoteOnly,以避免这些详细的错误信息暴露了程序代码细节从而引来黑客的入侵。
  下面我们添加一个页面CustomErrorsDemo.aspx,在它的Page_Load事件里抛出一个异常,代码如下:

复制代码
public partial class CustomErrorsDemo : System.Web.UI.Page 
{ 
    void Page_Load() void Page_Load(object sender, EventArgs e) 
    { 
      throw new Exception("故意抛出的异常。"); 
    } 
}
复制代码

先配置<customErrors>如下:

<customErrors mode="RemoteOnly"> 
    <error statusCode="403" redirect="NoAccess.htm" /> 
    <error statusCode="404" redirect="FileNotFound.htm" /> 
</customErrors>

  

[6]<error>子节点
  在<customErrors>节点下还包含有<error>子节点,这个节点主要是根据服务器的HTTP错误状态代码而重定向到我们自定义的错误页面,注意要使<error>子节点下的配置生效,必须将<customErrors>节点节点的Mode属性设置为“On”。下面是一个例子:
<customErrors mode="On" defaultRedirect="GenericErrorPage.htm"> 
    <error statusCode="403" redirect="403.htm" /> 
    <error statusCode="404" redirect="404.htm" /> 
</customErrors>

  在上面的配置中如果用户访问的页面不存在就会跳转到404.htm页面,如果用户没有权限访问请求的页面则会跳转到403.htm页面,403.htm和404.htm页面都是我们自己添加的页面,我们可以在页面中给出友好的错误提示。

[7]<httpHandlers>节点
  <httpHandlers>节点用于根据用户请求的URL和HTTP谓词将用户的请求交给相应的处理程序。可以在配置级别的任何层次配置此节点,也就是说可以针对某个特定目录下指定的特殊文件进行特殊处理。
  查看machine.config文件同一目录下的web.config文件中的<httpHandlers>节点配置:

<httpHandlers>
  ......
    <add path="*.mdf" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/> 
    <add path="*.ldf" verb="*" type="System.Web.HttpForbiddenHandler" validate="true"/> 
  ......
</httpHandlers>

  从上面的配置中可以看出,针对*.mdf、*.ldf文件的Get或者Post请求都会交给System.Web.HttpForbiddenHandler来处理,处理的结果就是用户不能查看或者下载相关的文件。如果我们某个文件夹下的文件或者某个类型的文件不允许用户下载,可以在</httpHandlers>节点中增加相应的子节点。
  下面我们以一个例子来说明<httpHandlers>节点的用法,在我们的asp.net应用程序中建立一个IPData目录,在IPData目录中创建一个IPData.txt文件,然后在Web.config中添加以下配置:

<httpHandlers> 
    <add path="IPData/*.txt" verb="*" type="System.Web.HttpForbiddenHandler"/> 
</httpHandlers>

  上面的代码的作用是禁止访问IPData目录下的任何txt文件。
  然后新建一个页面,在页面中添加一个超级链接,链接到该目录下IPData.txt文件,代码如下:
复制代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HttpHandlersDemo.aspx.cs" Inherits="HttpHandlersDemo" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"> 
    <title>httpHandlers节点的例子</title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
    <a href="IPData/IPData.txt" title="打开IPData/IPData.txt">打开IPData/IPData.txt</a> 
    </div> 
    </form> 
</body> 
</html>
复制代码

  运行这个页面的效果如下:
  

 
  当前web.config文件的<customErrors>节点配置如下:
  <customErrors mode="On" defaultRedirect="GenericErrorPage.htm"> 
      <error statusCode="403" redirect="403.htm" /> 
      <error statusCode="404" redirect="404.htm" /> 
  </customErrors>
  如果存在403.htm和404.htm页面,点击超级链接之后会出现如下效果:
  
  我们从上图中可以看到当<customErrors>节点的Mode属性为“On”时,因为被禁止访问IPData文件夹下的所有txt文件,所以会跳转到自定义的没有权限提示页面,即403.htm。

[8]<httpRuntime>节点
  <httpRuntime>节点用于对 ASP.NET HTTP 运行库设置。该节可以在计算机、站点、应用程序和子目录级别声明。
  例如下面的配置控制用户最大能上传的文件为40M(40*1024K),最大超时时间为60秒,最大并发请求为100个。
<httpRuntime maxRequestLength="40960" executionTimeout="60" appRequestQueueLimit="100"/>

[9]<pages>节点

<pages>节点用于表示对特定页设置,主要有三个属性,分别如下:
属性名           说明
buffer          是否启用了 HTTP 响应缓冲。
enableViewStateMac   是否应该对页的视图状态运行计算机身份验证检查 (MAC),以放置用户篡改,默认为false,如果设置为true将会引起性能的降低。
validateRequest     是否验证用户输入中有跨站点脚本攻击和SQL注入式漏洞攻击,默认为true,如果出现匹配情况就会发 HttpRequestValidationException 异常。对于包含有在线文本编辑器页面一般自行验证用户输入而将此属性设为false。

下面就是一个配置节点的例子:
<pages buffer="true" enableViewStateMac="true" validateRequest="false"/>

[10]<sessionState>节点
<sessionState>节点用于配置当前asp.net应用程序的会话状态配置。以下就是一个常见配置:

<sessionState cookieless="false" mode="InProc" timeout="30" />

       上面的节点配置是设置在asp.net应用程序中启用Cookie,并且指定会话状态模式为在进程中保存会话状态,同时还指定了会话超时为30分钟。
<sessionState>节点的Mode属性可以是以下几种值之一:
属性值       说明
Custom     使用自定义数据来存储会话状态数据。
InProc       默认值。由asp.net辅助进程来存储会话状态数据。
Off        禁用会话状态。
SQLServer    使用进程外SQL Server数据库保存会话状态数据。
StateServer    使用进程外 ASP.NET 状态服务存储状态信息。
  一般默认情况下使用InProc模式来存储会话状态数据,这种模式的好处是存取速度快,缺点是比较占用内存,所以不宜在这种模式下存储大型的用户会话数据。
[11]<globalization>节点:
  用于配置应用程序的全球化设置。此节点有几个比较重要的属性,分别如下:
属性名           说明
fileEncoding     可选属性。设置.aspx、.asmx 和 .asax 文件的存储编码。
requestEncoding    可选属性。设置客户端请求的编码,默认为UTF-8.
responseEncoding  可选属性。设置服务器端响应的编码,默认为UTF-8.
以下就是asp.net应用程序中的默认配置:

<globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8"/>

 
3、配置文件的读写操作
  虽然web.config文件是一个XML文件,但是由于权限的原因它在部署中不能像操作普通XML文件那样进行修改,在.net中提供了一个类用于对web.config进行修改。
  下面是针对web.config修改通用类的代码:

复制代码
using System; 
using System.Configuration; 
using System.Web; 
using System.Web.Configuration; 
/// <summary>    
/// ConfigurationOperator 的摘要说明    
/// </summary>    
public class ConfigurationOperator:IDisposable 
{ 
    private Configuration config; 

    ConfigurationOperator():this(HttpContext.Current.Request.ApplicationPath) 
    { 
        
    } 

    ConfigurationOperator(string path) 
    { 
        config = WebConfigurationManager.OpenWebConfiguration(path); 
    } 

    /// <summary>     
    /// 设置应用程序配置节点,如果已经存在此节点,则会修改该节点的值,否则添加此节点    
    /// </summary>     
    /// <param name="key">节点名称</param>     
    /// <param name="value">节点值</param>     
    void SetAppSetting(string key, string value) 
    { 
        AppSettingsSection appSetting = (AppSettingsSection)config.GetSection("appSettings"); 
        if (appSetting.Settings[key] == null)//如果不存在此节点,则添加     
        { 
            appSetting.Settings.Add(key, value); 
        } 
        else//如果存在此节点,则修改     
        { 
            appSetting.Settings[key].Value = value; 
        } 
    } 

    /// <summary>     
    /// 设置数据库连接字符串节点,如果不存在此节点,则会添加此节点及对应的值,存在则修改     
    /// </summary>     
    /// <param name="key">节点名称</param>     
    /// <param name="value">节点值</param>     
    void SetConnectionString(string key, string connectionString) 
    { 
        ConnectionStringsSection connectionSetting = (ConnectionStringsSection)config.GetSection("connectionStrings"); 
        if (connectionSetting.ConnectionStrings[key] == null)//如果不存在此节点,则添加     
        { 
            ConnectionStringSettings connectionStringSettings = new ConnectionStringSettings(key, connectionString); 
            connectionSetting.ConnectionStrings.Add(connectionStringSettings); 
        } 
        else//如果存在此节点,则修改     
        { 
            connectionSetting.ConnectionStrings[key].ConnectionString = connectionString; 
        } 
    } 

    /// <summary>     
    /// 保存所作的修改     
    /// </summary>     
    void Save() 
    { 
        config.Save(); 
        config = null; 
    } 

    void Dispose() 
    { 
        if (config != null) 
        { 
            config.Save(); 
        } 
    } 
} 
复制代码


  把上面的代码存放到App_Code文件夹下,我们在项目中就可以直接使用了。
  我们通过一个例子演示如果使用这个通用类对web.config进行设置。新建一个aspx页面,下面是前台代码:

复制代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ConfigModifyDemo.aspx.cs" Inherits="ConfigModifyDemo" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"> 
    <title>在部署后修改web.config的例子</title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
    <table border="0" cellpadding="0" cellspacing="0"> 
    <tr><td>类型</td><td>名称</td><td>值</td></tr> 
    <tr><td> 
    程序配置</td><td> 
    <asp:TextBox ID="txtKey" runat="server"></asp:TextBox> 
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtKey" 
    ErrorMessage="*" Display="Dynamic"></asp:RequiredFieldValidator></td><td> 
    <asp:TextBox ID="txtAppSetting" runat="server"></asp:TextBox></td></tr> 
    <tr><td> 
    数据库连接</td><td> 
    <asp:TextBox ID="txtConnectionName" runat="server"></asp:TextBox> 
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="txtConnectionName" 
    Display="Dynamic"></asp:RequiredFieldValidator></td><td style="height: 24px"> <asp:TextBox ID="txtConnectionString" runat="server"></asp:TextBox></td></tr> <tr><td> <asp:Button ID="btnModify" runat="server" OnClick="btnModify_Click" Text="修改" /></td><td></td><td></td></tr> </table> </div> </form> </body> </html>
复制代码
  编写后台代码有时可能需要增加对配置文件读写操作类所在dll (System.Configuration) 的引用,如下:
  
  下面是后台代码:
 
  后台Code

  下面是运行界面:
  

我们在上面的表单中填入如下信息:
  
假设此时web.config文件相关节点的内容如下:
<appSettings> 
    </appSettings> 
    <connectionStrings> 
        <add name="Conn" connectionString="Data Source=(local);Initial Catalog=AspNetStudy;Persist Security Info=True;User ID=sa;Password=sa" /> 
    </connectionStrings>
我们点击“修改”按钮之后的文件内容如下:
<appSettings> 
        <add key="country" value="china" /> 
    </appSettings> 
    <connectionStrings> 
        <add name="Conn" connectionString="Data Source=(local);Initial Catalog=Study;User ID=sa;Password=sa" 
            providerName="System.Data.SqlClient" /> 
    </connectionStrings>
        从执行结果可以看出我们的程序确实能做到修改和添加web.config中的节点的功能。需要注意的是,在利用了某些版本控制软件之后(如Microsoft Visual SourceSafe),版本控制软件可能会将web.config设置为只读属性,就会出现不能设置的情况,我们需要手动将web.config的只读属性去掉才能设置web.config文件。在实际部署项目的时候就不会存在这个问题。
        总结:web.config是asp.net应用程序中一个很重要的配置文件,通过web.config文件可以方便我们进行开发和部署asp.net应用程序。此外还能对程序进行一些灵活的控制。在本篇中详细讲述了各节点的作用。因为在部署asp.net应用程序后因为权限原因不能按照XML方式进行修改web.config文件,所以在本篇中还提供了一个针对<appSettings>节点和<connectionStrings>节点设置的通用类。

  由于Web.config在使用时很灵活,可以自定义一些节点。所以这里只介绍一些比较常用的节点。

复制代码
<?xml version="1.0"?>

<!--注意: 除了手动编辑此文件以外,您还可以使用 Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的“项目”->“Asp.Net 配置”选项。
设置和注释的完整列表在 machine.config.comments 中,该文件通常位于 "Windows" Microsoft.Net"Framework"v2.x"Config 中。-->

<!--Webconfig文件是一个xml文件,configuration 是xml文件的根节点,由于xml文件的根节点只能有一个,所以Webconfig的所有配置都是在这个节点内进行的。-->
<configuration>

  <!--指定配置节和命名空间声明。clear:移除对继承的节和节组的所有引用,只允许由当前 section 和 sectionGroup 元素添加的节和节组。
  remove:移除对继承的节和节组的引用。-->
  <configSections>
    <!--sectionGroup:定义配置节处理程序与配置节之间的关联-->
    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
      <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
        <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
        </sectionGroup>
      </sectionGroup>

      <!--section:定义配置节处理程序与配置元素之间的关联-->
      <section name="rewriter" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />

  </configSections>

  <!--appSettings是应用程序设置,可以定义应用程序的全局常量设置等信息-->
  <appSettings>
    <add key="1" value="1" />
    <add key="gao" value="weipeng" />
  </appSettings>

  <!--连接字符串设置-->
  <connectionStrings>
    <add name="ConnString" connectionString="Data Source=GAO;Initial Catalog=HBWXDate;User ID=sa;password=sa"></add>
    <add name="111" connectionString="11111" />
  </connectionStrings>

  <!--指定应用子配置设置的资源,并锁定配置设置,以防止它们被子配置文件重写。page指定应用包含的配置设置的资源.allowOverride是否允许配置文件的重写,提高配置文件的安全性-->
  <location path="Default.aspx" allowOverride="false">

    <!--控制asp.net运行时的行为-->
    <system.web>

      <!--identity控制web应用程序的身份验证标识.-->
      <identity impersonate="false" />

      <!--标识特定于页的配置设置(如是否启用会话状态、视图状态,是否检测用户的输入等)。<pages>可以在计算机、站点、应用程序和子目录级别声明.
        以下设置是默认主页为Index,主题是Default,不检测用户在浏览器输入的内容中是否存在潜在的危险数据(注:该项默认是检测,如果你使用了不检测,一要对用户的输入进行编码或验证),在从客户端回发页时将检查加密的视图状态,以验证视图状态是否已在客户端被篡改。(注:该项默认是不验证)禁用ViewState-->
      <pages masterPageFile="Index" theme="Default" buffer="true" enableViewStateMac="true" validateRequest="false" enableViewState="false">

        <!--controls 元素定义标记前缀所在的 register 指令和命名空间的集合-->
        <controls></controls>

        <!--将在程序集预编译期间使用的导入指令的集合-->
        <namespaces></namespaces>

      </pages>

      <!--默认错误页设置,mode:具有On,Off,RemoteOnly 3种状态。On表示始终显示自定义的信息; Off表示始终显示详细的asp.net错误信息; RemoteOnly表示只对不在本地Web服务器上运行的用户显示自定义信息.defaultRedirect:用于出现错误时重定向的URL地址-->
      <customErrors defaultRedirect="Err.html" mode="RemoteOnly">
        <!--特殊代码编号的错误从定向文件-->
        <error statusCode="403" redirect="NoAccess.htm" />
        <error statusCode="404" redirect="FileNotFound.htm" />
      </customErrors>

      <!--配置调试和跟踪:下面配置的意思是启动调试(默认),捕获跟踪信息,要缓存的跟踪请求个数(15),跟踪结果的排列顺序-->
      <trace enabled="true" localOnly="false" pageOutput="true" requestLimit="15" traceMode="SortByCategory"/>

      <!-- 设置 debug="true" 将调试符号插入已编译的页面中。但由于这会影响性能,因此只在开发过程中将此值设置为 true。设置默认的开发语言C#。batch是否支持批处理-->
      <compilation debug="true" defaultLanguage="c#" batch="false">

        <assemblies>
          <!--加的程序集引用,每添加一个程序集,就表示你的应用程序已经依赖了一个程序集,你就可以在你的应用程序中使用了-->
          <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
          <add assembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
          <add assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
          <add assembly="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
          <add assembly="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
          <add assembly="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
          <add assembly="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
          <add assembly="System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
          <add assembly="System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        </assemblies>

        <!--定义用于编译自定义资源文件的生成提供程序的集合。-->
        <buildProviders>
          <!---->
          <add extension=".aspx" type="System.Web.Compilation.PageBuildProvider"/>
          <add extension=".ascx" type="System.Web.Compilation.UserControlBuildProvider"/>
          <add extension=".master" type="System.Web.Compilation.MasterPageBuildProvider"/>
          <add extension=".asmx" type="System.Web.Compilation.WebServiceBuildProvider"/>
          <add extension=".ashx" type="System.Web.Compilation.WebHandlerBuildProvider"/>
          <add extension=".soap" type="System.Web.Compilation.WebServiceBuildProvider"/>
          <add extension=".resx" type="System.Web.Compilation.ResXBuildProvider"/>
          <add extension=".resources" type="System.Web.Compilation.ResourcesBuildProvider"/>
          <add extension=".wsdl" type="System.Web.Compilation.WsdlBuildProvider"/>
          <add extension=".xsd" type="System.Web.Compilation.XsdBuildProvider"/>
          <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
        </buildProviders>

      </compilation>

      <!--通过 <authentication> 节可以配置 ASP.NET 使用的 安全身份验证模式,以标识传入的用户。
      Windows: 使用IIS验证方式;Forms: 使用基于窗体的验证方式;Passport: 采用Passport cookie验证模式,;one: 不采用任何验证方式-->
      <authentication mode="Forms">
        <!--Name: 指定完成身份验证的Http cookie的名称;LoginUrl: 如果未通过验证或超时后重定向的页面URL,一般为登录页面,让用户重新登录;
          Protection: 指定 cookie数据的保护方式,可设置为:All表示加密数据,并进行有效性验证两种方式,None表示不保护Cookie,Encryption表示对Cookie内容进行加密,validation表示对Cookie内容进行有效性验证,
          TimeOut: 指定Cookie的失效时间. 超时后要重新登录。-->
        <forms name=".ASPXUSERDEMO" loginUrl="Login.aspx" protection="All" timeout="30"/>
      </authentication>

      <!--控制对 URL 资源的客户端访问(如允许匿名用户访问)。此元素可以在任何级别(计算机、站点、应用程序、子目录或页)上声明。必需与<authentication> 节配合使用。
      此处的意思是对匿名用户不进行身份验证。拒绝用户customer-->
      <authorization>
        <allow users="*"/>
        <deny users="customer"/>
        <allow users="aa" roles="aa" />
      </authorization>

      <!--站点全球化设置,requestEncoding: 它用来检查每一个发来请求的编码;responseEncoding: 用于检查发回的响应内容编码;
      fileEncoding:用于检查aspx,asax等文件解析的默认编码,默认的编码是utf-8-->
      <globalization requestEncoding="gb2312" responseEncoding="gb2312" fileEncoding="gb2312" />

      <!--会话状态设置。mode: 分为off,Inproc,StateServer,SqlServer几种状态 InProc 存储在进程中特点:具有最佳的性能,速度最快,但不能跨多台服务器存储共享; 
      StateServer 存储在状态服务器中特点:当需要跨服务器维护用户会话信息时,使用此方法。但是信息存储在状态服务器上,一旦状态服务器出现故障,信息将丢失;
      SqlServer 存储在sql server中特点:工作负载会变大,但信息不会丢失; stateConnectionString :指定asp.net应用程序存储远程会话状态的服务器名,默认为本机。
      sqlConnectionString:当用会话状态数据库时,在这里设置连接字符串。Cookieless:设置为flase时,表示使用cookie会话状态来标识客户.timeout表示会话超时时间。-->
      <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="20"></sessionState>

      <!--为 ASP.NET 应用程序配置页的视图状态设置。设置要存储在页历史记录中的项数。-->
      <sessionPageState historySize="9"/>

      <!--配置asp.net http运行库的设置。可以在计算机,站点,应用程序和子目录级别声明
    允许最多的请求个数100,最长允许执行请求时间为80秒,控制用户上传文件的大小,默认是4M。useFullyQualifiedRedirectUrl客户端重定向不需要被自动转换为完全限定格式。-->
      <httpRuntime appRequestQueueLimit="100" executionTimeout="80" maxRequestLength="40960" useFullyQualifiedRedirectUrl="false"/>

      <!--httpModules在一个应用程序内配置 HTTP 模块。-->
      <httpModules>
        <add name="OutputCache" type="System.Web.Caching.OutputCacheModule" />
        <add name="Session" type="System.Web.SessionState.SessionStateModule" />
        <add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule" />
        <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
        <add name="PassportAuthentication" type="System.Web.Security.PassportAuthenticationModule" />
        <add name="RoleManager" type="System.Web.Security.RoleManagerModule" />
        <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" />
        <add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule" />
        <add name="AnonymousIdentification" type="System.Web.Security.AnonymousIdentificationModule" />
        <!--自定义的URL重写,type基本上就是dll名-->
        <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" />
        <add name="Profile" type="System.Web.Profile.ProfileModule" />
      </httpModules>

      <!--httpHandlers用于根据用户请求的URL和HTTP谓词将用户的请求交给相应的处理程序。可以在配置级别的任何层次配置此节点,也就是说可以针对某个特定目录下指定的特殊文件进行特殊处理。
    add:指定映射到处理程序的谓词/路径。clear:移除当前已配置或已继承的所有处理程序映射。remove:移除映射到处理程序的谓词/路径。remove 指令必须与前一个 add 指令的谓词/路径组合完全匹配。该指令不支持通配符。-->
      <httpHandlers>
        <remove verb="*" path="*.asmx"/>
        <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
        <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro.2"/>
      </httpHandlers>

      <!--为 Web 应用程序使用的 Cookie 配置属性。domain:设置 Cookie 域名。httpOnlyCookies:在 Internet Explorer 6 SP1 中启用 HttpOnlyCookies Cookie 的输出。默认值为 false。requireSSL:获取一个指示是否需要安全套接字层 (SSL) 通信的值.-->
      <httpCookies httpOnlyCookies="false" requireSSL="false"/>
      <!--控制 ASP.NET Web 服务及其客户端的行为。protocols:指定传输协议,ASP.NET 可使用这些传输协议来解密 HTTP-->
      <webServices>
        <protocols>
          <add/>
        </protocols>
      </webServices>

      <!--为 Web 应用程序配置缓存设置。cache:定义全局应用程序缓存设置。outputCache :指定应用程序范围的输出缓存设置。outputCacheSettings:指定可以应用于应用程序中页的输出缓存设置。sqlCacheDependency:为 ASP.NET 应用程序配置 SQL 缓存依赖项。-->
      <caching>
        <cache disableMemoryCollection = "false" disableExpiration = "false" privateBytesLimit = "0" percentagePhysicalMemoryUsedLimit = "90" privateBytesPollTime = "00:02:00"/>
        <!--设计需要以这种方式缓存的页时,您需要向该页添加以下指令:<%@ OutputCache CacheProfile="ServerOnly" %>-->
        <outputCacheSettings>
          <outputCacheProfiles>
            <add name="ServerOnly" duration="60" varyByCustom="browser" location="Server" />
          </outputCacheProfiles>
        </outputCacheSettings>
      </caching>
    </system.web>
  </location>

  <!--网络设置,authenticationModules:指定用于对 Internet 请求进行身份验证的模块。connectionManagement:指定与 Internet 宿主的连接的最大数目。defaultProxy:配置超文本传输协议 (HTTP) 代理服务器。
  mailSettings:配置简单邮件传输协议 (SMTP) 邮件发送选项。requestCaching:控制网络请求的缓存机制。settings:配置 System.Net 的基本网络选项。-->
  <system.net>
    <!--配置SMTP电子邮件设置-->
    <mailSettings>
      <smtp from="weipeng">
        <network host="Gao" password="" userName="" />
      </smtp>
    </mailSettings>

    <!--禁用所有缓存-->
    <requestCaching disableAllCaching="true"></requestCaching>

    <!--指定代理地址,并对本地访问和 contoso.com 跳过代理。-->
    <defaultProxy>
      <proxy usesystemdefault="True" proxyaddress="http://192.168.1.10:3128" bypassonlocal="True"/>
      <bypasslist>
        <add address="[a-z]+".contoso=""".com" />
      </bypasslist>
    </defaultProxy>

  </system.net>

  <!--该节替换在 httpHandlers 和 httpModules 节中添加的与 AJAX 相关的 HTTP 处理程序和模块。该节使 IIS 7.0 在集成模式下运行时可使用这些处理程序和模块。在iis7.0 下运行 ASP.NET AJAX 需要 system.webServer 
  节。对早期版本的 IIS 来说则不需要此节。 -->
  <system.webServer>

    <validation validateIntegratedModeConfiguration="false"/>
    <modules>
      <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </modules>

    <handlers>
      <remove name="WebServiceHandlerFactory-Integrated"/>
      <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </handlers>

  </system.webServer>

  <!--ASP.NET AJAX 中配置 ASP.NET 服务-->
  <system.web.extensions>

    <!--配置 JSON 序列化-->
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="5000"/>
      </webServices>
    </scripting>

  </system.web.extensions>

  <!--对WCF的相关配置-->
  <system.serviceModel>

    <services>
      <service name="WCFStudent.WCFStudentText" behaviorConfiguration="ServiceBehavior">
        <!-- Service Endpoints -->
        <endpoint address="" binding="wsHttpBinding" contract="WCFStudent.IStuServiceContract">
          <!-- 部署时,应删除或替换下列标识元素,以反映在其下运行部署服务的标识。删除之后,WCF 将自动推导相应标识。-->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息-->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>

  <!--URL重定向-->
  <rewriter>
    <rewrite url="~/user/u(.+).aspx" to="~/user/index.aspx?r=$1" />
    <rewrite url="~/ask/q(.+).aspx" to="~/home/ask/content.aspx?id=$1" />
    <rewrite url="~/blog/b(.+).aspx" to="~/home/blog/article.aspx?r=$1" />
    <rewrite url="~/news/n(.+).aspx" to="~/home/news/content.aspx?nid=$1" />
    <rewrite url="~/default.aspx" to="~/home/ram/net.aspx" />
  </rewriter>

</configuration>
复制代码

 

<?xml version="1.0"?>

<!--注意: 除了手动编辑此文件以外,您还可以使用 Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的“项目”->“Asp.Net 配置”选项。
设置和注释的完整列表在 machine.config.comments 中,该文件通常位于 "Windows" Microsoft.Net"Framework"v2.x"Config 中。-->

<!--Webconfig文件是一个xml文件,configuration 是xml文件的根节点,由于xml文件的根节点只能有一个,所以Webconfig的所有配置都是在这个节点内进行的。-->
<configuration>

  <!--指定配置节和命名空间声明。clear:移除对继承的节和节组的所有引用,只允许由当前 section 和 sectionGroup 元素添加的节和节组。
  remove:移除对继承的节和节组的引用。-->
  <configSections>
    <!--sectionGroup:定义配置节处理程序与配置节之间的关联-->
    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
      <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
        <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
        </sectionGroup>
      </sectionGroup>

      <!--section:定义配置节处理程序与配置元素之间的关联-->
      <section name="rewriter" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />

  </configSections>

  <!--appSettings是应用程序设置,可以定义应用程序的全局常量设置等信息-->
  <appSettings>
    <add key="1" value="1" />
    <add key="gao" value="weipeng" />
  </appSettings>

  <!--连接字符串设置-->
  <connectionStrings>
    <add name="ConnString" connectionString="Data Source=GAO;Initial Catalog=HBWXDate;User ID=sa;password=sa"></add>
    <add name="111" connectionString="11111" />
  </connectionStrings>

  <!--指定应用子配置设置的资源,并锁定配置设置,以防止它们被子配置文件重写。page指定应用包含的配置设置的资源.allowOverride是否允许配置文件的重写,提高配置文件的安全性-->
  <location path="Default.aspx" allowOverride="false">

    <!--控制asp.net运行时的行为-->
    <system.web>

      <!--identity控制web应用程序的身份验证标识.-->
      <identity impersonate="false" />

      <!--标识特定于页的配置设置(如是否启用会话状态、视图状态,是否检测用户的输入等)。<pages>可以在计算机、站点、应用程序和子目录级别声明.
        以下设置是默认主页为Index,主题是Default,不检测用户在浏览器输入的内容中是否存在潜在的危险数据(注:该项默认是检测,如果你使用了不检测,一要对用户的输入进行编码或验证),在从客户端回发页时将检查加密的视图状态,以验证视图状态是否已在客户端被篡改。(注:该项默认是不验证)禁用ViewState-->
      <pages masterPageFile="Index" theme="Default" buffer="true" enableViewStateMac="true" validateRequest="false" enableViewState="false">

        <!--controls 元素定义标记前缀所在的 register 指令和命名空间的集合-->
        <controls></controls>

        <!--将在程序集预编译期间使用的导入指令的集合-->
        <namespaces></namespaces>

      </pages>

      <!--默认错误页设置,mode:具有On,Off,RemoteOnly 3种状态。On表示始终显示自定义的信息; Off表示始终显示详细的asp.net错误信息; RemoteOnly表示只对不在本地Web服务器上运行的用户显示自定义信息.defaultRedirect:用于出现错误时重定向的URL地址-->
      <customErrors defaultRedirect="Err.html" mode="RemoteOnly">
        <!--特殊代码编号的错误从定向文件-->
        <error statusCode="403" redirect="NoAccess.htm" />
        <error statusCode="404" redirect="FileNotFound.htm" />
      </customErrors>

      <!--配置调试和跟踪:下面配置的意思是启动调试(默认),捕获跟踪信息,要缓存的跟踪请求个数(15),跟踪结果的排列顺序-->
      <trace enabled="true" localOnly="false" pageOutput="true" requestLimit="15" traceMode="SortByCategory"/>

      <!-- 设置 debug="true" 将调试符号插入已编译的页面中。但由于这会影响性能,因此只在开发过程中将此值设置为 true。设置默认的开发语言C#。batch是否支持批处理-->
      <compilation debug="true" defaultLanguage="c#" batch="false">

        <assemblies>
          <!--加的程序集引用,每添加一个程序集,就表示你的应用程序已经依赖了一个程序集,你就可以在你的应用程序中使用了-->
          <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
          <add assembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
          <add assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
          <add assembly="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
          <add assembly="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
          <add assembly="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
          <add assembly="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
          <add assembly="System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
          <add assembly="System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        </assemblies>

        <!--定义用于编译自定义资源文件的生成提供程序的集合。-->
        <buildProviders>
          <!---->
          <add extension=".aspx" type="System.Web.Compilation.PageBuildProvider"/>
          <add extension=".ascx" type="System.Web.Compilation.UserControlBuildProvider"/>
          <add extension=".master" type="System.Web.Compilation.MasterPageBuildProvider"/>
          <add extension=".asmx" type="System.Web.Compilation.WebServiceBuildProvider"/>
          <add extension=".ashx" type="System.Web.Compilation.WebHandlerBuildProvider"/>
          <add extension=".soap" type="System.Web.Compilation.WebServiceBuildProvider"/>
          <add extension=".resx" type="System.Web.Compilation.ResXBuildProvider"/>
          <add extension=".resources" type="System.Web.Compilation.ResourcesBuildProvider"/>
          <add extension=".wsdl" type="System.Web.Compilation.WsdlBuildProvider"/>
          <add extension=".xsd" type="System.Web.Compilation.XsdBuildProvider"/>
          <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
        </buildProviders>

      </compilation>

      <!--通过 <authentication> 节可以配置 ASP.NET 使用的 安全身份验证模式,以标识传入的用户。
      Windows: 使用IIS验证方式;Forms: 使用基于窗体的验证方式;Passport: 采用Passport cookie验证模式,;one: 不采用任何验证方式-->
      <authentication mode="Forms">
        <!--Name: 指定完成身份验证的Http cookie的名称;LoginUrl: 如果未通过验证或超时后重定向的页面URL,一般为登录页面,让用户重新登录;
          Protection: 指定 cookie数据的保护方式,可设置为:All表示加密数据,并进行有效性验证两种方式,None表示不保护Cookie,Encryption表示对Cookie内容进行加密,validation表示对Cookie内容进行有效性验证,
          TimeOut: 指定Cookie的失效时间. 超时后要重新登录。-->
        <forms name=".ASPXUSERDEMO" loginUrl="Login.aspx" protection="All" timeout="30"/>
      </authentication>

      <!--控制对 URL 资源的客户端访问(如允许匿名用户访问)。此元素可以在任何级别(计算机、站点、应用程序、子目录或页)上声明。必需与<authentication> 节配合使用。
      此处的意思是对匿名用户不进行身份验证。拒绝用户customer-->
      <authorization>
        <allow users="*"/>
        <deny users="customer"/>
        <allow users="aa" roles="aa" />
      </authorization>

      <!--站点全球化设置,requestEncoding: 它用来检查每一个发来请求的编码;responseEncoding: 用于检查发回的响应内容编码;
      fileEncoding:用于检查aspx,asax等文件解析的默认编码,默认的编码是utf-8-->
      <globalization requestEncoding="gb2312" responseEncoding="gb2312" fileEncoding="gb2312" />

      <!--会话状态设置。mode: 分为off,Inproc,StateServer,SqlServer几种状态 InProc 存储在进程中特点:具有最佳的性能,速度最快,但不能跨多台服务器存储共享; 
      StateServer 存储在状态服务器中特点:当需要跨服务器维护用户会话信息时,使用此方法。但是信息存储在状态服务器上,一旦状态服务器出现故障,信息将丢失;
      SqlServer 存储在sql server中特点:工作负载会变大,但信息不会丢失; stateConnectionString :指定asp.net应用程序存储远程会话状态的服务器名,默认为本机。
      sqlConnectionString:当用会话状态数据库时,在这里设置连接字符串。Cookieless:设置为flase时,表示使用cookie会话状态来标识客户.timeout表示会话超时时间。-->
      <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="20"></sessionState>

      <!--为 ASP.NET 应用程序配置页的视图状态设置。设置要存储在页历史记录中的项数。-->
      <sessionPageState historySize="9"/>

      <!--配置asp.net http运行库的设置。可以在计算机,站点,应用程序和子目录级别声明
    允许最多的请求个数100,最长允许执行请求时间为80秒,控制用户上传文件的大小,默认是4M。useFullyQualifiedRedirectUrl客户端重定向不需要被自动转换为完全限定格式。-->
      <httpRuntime appRequestQueueLimit="100" executionTimeout="80" maxRequestLength="40960" useFullyQualifiedRedirectUrl="false"/>

      <!--httpModules在一个应用程序内配置 HTTP 模块。-->
      <httpModules>
        <add name="OutputCache" type="System.Web.Caching.OutputCacheModule" />
        <add name="Session" type="System.Web.SessionState.SessionStateModule" />
        <add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule" />
        <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
        <add name="PassportAuthentication" type="System.Web.Security.PassportAuthenticationModule" />
        <add name="RoleManager" type="System.Web.Security.RoleManagerModule" />
        <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" />
        <add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule" />
        <add name="AnonymousIdentification" type="System.Web.Security.AnonymousIdentificationModule" />
        <!--自定义的URL重写,type基本上就是dll名-->
        <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" />
        <add name="Profile" type="System.Web.Profile.ProfileModule" />
      </httpModules>

      <!--httpHandlers用于根据用户请求的URL和HTTP谓词将用户的请求交给相应的处理程序。可以在配置级别的任何层次配置此节点,也就是说可以针对某个特定目录下指定的特殊文件进行特殊处理。
    add:指定映射到处理程序的谓词/路径。clear:移除当前已配置或已继承的所有处理程序映射。remove:移除映射到处理程序的谓词/路径。remove 指令必须与前一个 add 指令的谓词/路径组合完全匹配。该指令不支持通配符。-->
      <httpHandlers>
        <remove verb="*" path="*.asmx"/>
        <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
        <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro.2"/>
      </httpHandlers>

      <!--为 Web 应用程序使用的 Cookie 配置属性。domain:设置 Cookie 域名。httpOnlyCookies:在 Internet Explorer 6 SP1 中启用 HttpOnlyCookies Cookie 的输出。默认值为 false。requireSSL:获取一个指示是否需要安全套接字层 (SSL) 通信的值.-->
      <httpCookies httpOnlyCookies="false" requireSSL="false"/>
      <!--控制 ASP.NET Web 服务及其客户端的行为。protocols:指定传输协议,ASP.NET 可使用这些传输协议来解密 HTTP-->
      <webServices>
        <protocols>
          <add/>
        </protocols>
      </webServices>

      <!--为 Web 应用程序配置缓存设置。cache:定义全局应用程序缓存设置。outputCache :指定应用程序范围的输出缓存设置。outputCacheSettings:指定可以应用于应用程序中页的输出缓存设置。sqlCacheDependency:为 ASP.NET 应用程序配置 SQL 缓存依赖项。-->
      <caching>
        <cache disableMemoryCollection = "false" disableExpiration = "false" privateBytesLimit = "0" percentagePhysicalMemoryUsedLimit = "90" privateBytesPollTime = "00:02:00"/>
        <!--设计需要以这种方式缓存的页时,您需要向该页添加以下指令:<%@ OutputCache CacheProfile="ServerOnly" %>-->
        <outputCacheSettings>
          <outputCacheProfiles>
            <add name="ServerOnly" duration="60" varyByCustom="browser" location="Server" />
          </outputCacheProfiles>
        </outputCacheSettings>
      </caching>
    </system.web>
  </location>

  <!--网络设置,authenticationModules:指定用于对 Internet 请求进行身份验证的模块。connectionManagement:指定与 Internet 宿主的连接的最大数目。defaultProxy:配置超文本传输协议 (HTTP) 代理服务器。
  mailSettings:配置简单邮件传输协议 (SMTP) 邮件发送选项。requestCaching:控制网络请求的缓存机制。settings:配置 System.Net 的基本网络选项。-->
  <system.net>
    <!--配置SMTP电子邮件设置-->
    <mailSettings>
      <smtp from="weipeng">
        <network host="Gao" password="" userName="" />
      </smtp>
    </mailSettings>

    <!--禁用所有缓存-->
    <requestCaching disableAllCaching="true"></requestCaching>

    <!--指定代理地址,并对本地访问和 contoso.com 跳过代理。-->
    <defaultProxy>
      <proxy usesystemdefault="True" proxyaddress="http://192.168.1.10:3128" bypassonlocal="True"/>
      <bypasslist>
        <add address="[a-z]+".contoso=""".com" />
      </bypasslist>
    </defaultProxy>

  </system.net>

  <!--该节替换在 httpHandlers 和 httpModules 节中添加的与 AJAX 相关的 HTTP 处理程序和模块。该节使 IIS 7.0 在集成模式下运行时可使用这些处理程序和模块。在iis7.0 下运行 ASP.NET AJAX 需要 system.webServer 
  节。对早期版本的 IIS 来说则不需要此节。 -->
  <system.webServer>

    <validation validateIntegratedModeConfiguration="false"/>
    <modules>
      <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </modules>

    <handlers>
      <remove name="WebServiceHandlerFactory-Integrated"/>
      <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </handlers>

  </system.webServer>

  <!--ASP.NET AJAX 中配置 ASP.NET 服务-->
  <system.web.extensions>

    <!--配置 JSON 序列化-->
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="5000"/>
      </webServices>
    </scripting>

  </system.web.extensions>

  <!--对WCF的相关配置-->
  <system.serviceModel>

    <services>
      <service name="WCFStudent.WCFStudentText" behaviorConfiguration="ServiceBehavior">
        <!-- Service Endpoints -->
        <endpoint address="" binding="wsHttpBinding" contract="WCFStudent.IStuServiceContract">
          <!-- 部署时,应删除或替换下列标识元素,以反映在其下运行部署服务的标识。删除之后,WCF 将自动推导相应标识。-->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息-->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

  </system.serviceModel>

  <!--URL重定向-->
  <rewriter>
    <rewrite url="~/user/u(.+).aspx" to="~/user/index.aspx?r=$1" />
    <rewrite url="~/ask/q(.+).aspx" to="~/home/ask/content.aspx?id=$1" />
    <rewrite url="~/blog/b(.+).aspx" to="~/home/blog/article.aspx?r=$1" />
    <rewrite url="~/news/n(.+).aspx" to="~/home/news/content.aspx?nid=$1" />
    <rewrite url="~/default.aspx" to="~/home/ram/net.aspx" />
  </rewriter>

</configuration>

转载于:https://www.cnblogs.com/asdyzh/p/9741634.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值