web.config

    1、通过VS建立一个默认的web.config文件。 

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <connectionStrings>
    <add name="ApplicationServices"
         connectionString="data source=.SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
         providerName="System.Data.SqlClient" />
  </connectionStrings>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />

    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
    </authentication>

    <membership>
      <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
             applicationName="/" />
      </providers>
    </membership>

    <profile>
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
      </providers>
    </profile>

    <roleManager enabled="false">
      <providers>
        <clear/>
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>

  </system.web>

  <system.webServer>
     <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>
View Code

   2、我们先对默认的配置文件进行说明下。

<Configuration>:根节点元素,其他的节都是在它的内部。

</Configuration>:根节点结束元素标签。


< connectionString >: 连接数据库字符串

       

    

     例如: add name="ApplicationServices" connectionString="data source=.SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"


nodedesciption
ApplicationServices 定义连接数据库的名字,自定义
connectionString 配置连接数据库的server database user pwd |windows验证
providerName 连接数据库的提供者程序


(1) < system.web >:是应用程序配置的一个组成部分。通常的一些应用程序,可用于配置系统的各个组成部分的Web组件。

nodepropertychildNodedescription
< compilation > debug NULL compilation: 编译,debug:bool值,为true时,表示启动aspx调试,false:不启动,一般项目开发阶段设为true,部署到客户机为false。 targetFramework:表示所使用的编译版本,如‘4.0’表示所使用的是.net framework 4.0
< targetFramework >
<authentication> <mode> <forms> authentication:数据验证,mode:验证模式NONE 默认,windows ,passPort,Forms,详情参见
<membership> NULL
<providers> <clear>
<and >
要使用membership,需要加上表单验证详情参见
<
原文地址:https://www.cnblogs.com/fandong90/p/5006318.html