首页 > 开发 > 综合 > 正文

web.config配置文件示例

2024-07-21 02:28:34
字体:
来源:转载
供稿:网友


为了方便配置web.config文件,我写了一个常用的web.config文件的示例,可以以此为模版根据需要修改。
创建web.config文件的三种快捷方法:
    1、用vs2005中的asp.net网站配置工具配置
    2、参考c:/windows/microsoft.net/framework/v2.0.50727(.net framework版本)/config/目录下的machine.config 文件进行编写
    3、以下边这个文件作模版修改


点击此处展开代码
<?xml version="1.0" encoding="utf-8"?>
<!--
    注意: 除了手动编辑此文件以外,您还可以使用
    web 管理工具来配置应用程序的设置。可以使用 visual studio 中的
     “网站”->“asp.net 配置”选项。
    设置和注释的完整列表在
    machine.config.comments 中,该文件通常位于
    /windows/microsoft.net/framework/v2.x/config 中
-->
<configuration xmlns="http://schemas.microsoft.com/.netconfiguration/v2.0">
  <appsettings>
    <!-- enable data caching -->
    <add key="enablecaching" value="true"/>
  </appsettings>
  <connectionstrings>
    <add name="strconnuserdb"
         connectionstring="data source=.;initial catalog=profile1;integrated security=true"
         providername="system.data.sqlclient" />
  </connectionstrings>
  <system.web>

    <membership>
      <providers>
        <remove name="aspnetsqlmembershipprovider" />
        <add name="aspnetsqlmembershipprovider"
             type="system.web.security.sqlmembershipprovider, system.web, version=2.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a"
             connectionstringname="strconnuserdb"
             enablepasswordretrieval="false"
             enablepasswordreset="true"
             requiresquestionandanswer="true"
             applicationname="/"
             requiresuniqueemail="false"
             passwordformat="hashed"
             maxinvalidpasswordattempts="5"
             minrequiredpasswordlength="7"
             minrequirednonalphanumericcharacters="1"
             passwordattemptwindow="10"
             passwordstrengthregularexpression=""
             description="存储membership数据"
         />
      </providers>
    </membership>
    <profile enabled="true" defaultprovider="aspnetsqlprofileprovider" inherits="">
      <providers>
      <remove name="aspnetsqlprofileprovider" />
      <add name="aspnetsqlprofileprovider"
            connectionstringname="strconnuserdb"
            applicationname="/"
            type="system.web.profile.sqlprofileprovider, system.web, version=2.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a"
            description="存储profile数据"
         />
      </providers>
       <properties>
        <add name="name"/>
        <add name="backcolor" type="system.drawing.color" allowanonymous="true" serializeas="binary"/>
      </properties>
    </profile>
   
    <rolemanager enabled="true" cacherolesincookie="true">
      <providers>
        <remove name="aspnetsqlroleprovider" />
        <add name="aspnetsqlroleprovider"
        connectionstringname="strconnuserdb"
        applicationname="/"
        type="system.web.security.sqlroleprovider, system.web, version=2.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a"
        description="存储role数据"
          />
      </providers>
    </rolemanager>
    <!-- other rolemanager attributes (and their defaults) include:
            cookiename=".aspxroles"       
            cookietimeout="30"
            cookiepath="/"       
            cookierequiressl="false"       
            cookieslidingexpiration="true"  // renew expiring cookies?
            createpersistentcookie="false"  // issue persistent cookie?
            cookieprotection="all" />          // cookie protection level
     -->
    <compilation debug="false" />
    <authentication mode="forms" />
    <!--
        <anonymousidentification
            enabled="true"
            cookiename=".aspxanonymous"
            cookietimeout="43200"
            cookiepath="/"
            cookierequiressl="false"
            cookieslidingexpiration="true"
            cookieprotection="all"
            cookieless="usecookies"
         />
     -->   
    <!--
        <customerrors mode="remoteonly" defaultredirect="genericerrorpage.htm">
            <error statuscode="403" redirect="noaccess.htm" />
            <error statuscode="404" redirect="filenotfound.htm" />
        </customerrors>
     -->
  </system.web>
  <location path="user">
    <system.web>
      <authorization>
        <allow roles="?" />
        <deny users="*"/>
      </authorization>
    </system.web>
  </location>
</configuration>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表