Web.config详解
一、认识Web.config文件
Web.config XML ASP.NET Web ASP.NET Web .NETWebWeb.configWeb.config
).Web.ConfigXML,
<configSections>
: <appSetting> .
3.
: <system.Web>Asp.net.
4.
: <sectionGroup><configSections><sectionGroup>.
().
.
2.<appSetting>
:
I.
<appSettings>
<add key="Conntction" value="server=192.168.85.66;userid=sa;password=;database=Info;"/>
<appSettings>
.
II.<appSettings>
<add key="ErrPage" value="Error.aspx"/>
<appSettings>
.
3.<compilation>
:
<compilation
defaultLanguage="c#"
debug="true"
/>
I.default language: ,C#VB.net.
IIdebug : trueaspx falseaspx
true,false.
4.<customErrors>
:
<customErrors
mode="RemoteOnly"
defaultRedirect="error.aspx"
<error statusCode="440" redirect="err440page.aspx"/>
<error statusCode="500" redirect="err500Page.aspx"/>
/>
I.mode : On,Off,RemoteOnly 3On; Offasp.net; RemoteOnlyWeb.
II.defaultRedirect: URL.
.
IV. redirect:URL.
5.<globalization>
:
<globalization
requestEncoding="utf-8"
responseEncoding="utf-8"
fileEncoding="utf-8"
/>
I.requestEncoding: .
II.responseEncoding: .
III.fileEncoding: aspx,asax.
6.<sessionState>
:
<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
cookieless="false"
timeout="20"
/>
I.mode: off,Inproc,StateServer,SqlServer
II. stateConnectionString :Asp.net
truecookie .
V. TimeOut: .
7.<authentication>
:
<authentication mode="Forms">
<forms name=".ASPXUSERDEMO" loginUrl="Login.aspx" protection="All" timeout="30"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
I.Windows: IIS
Passport cookie
Forms:
I.Name: Http cookie.
II.LoginUrl: URL
cookie.
: All None Encryption Validation
Cookie.
c. EncryptionCookie
Cookie
Cookie. .
Web.config<processModel> Web.config文件是可以扩展的。你可以自定义新配置参数并编写配置节处理程序以对它们进行处理。
web.config
<configuration>
<system.web>
</system.web>
</configuration>
XML标记。
1<authentication>
ASP.NET WindowsFormsPassPortNone< authentication> <authorization> 节配合使用。
示例:
Forms
<authentication mode="Forms" >
<forms loginUrl="logon.aspx" name=".FormsAuthCookie"/>
</authentication>
loginUrlnameCookie名称。
2<authorization>
URL <authentication> 节配合使用。
<authorization>
<deny users="?"/>
</authorization>
user.identity.nameweb.Security.FormsAuthentication.RedirectFromLoginPage.具体的
3<compilation>
ASP.NET debug“True”.FalseWeb.config文件中有详细说明,此处省略示例)
4<customErrors>
ASP.NET XML Web services 中发生的错误。
<customErrors defaultRedirect="ErrorPage.aspx" mode="RemoteOnly">
</customErrors>
defaultRedirectmode Web ()信息。
5<httpRuntime>
ASP.NET HTTP 运行库设置。该节可以在计算机、站点、应用程序和子目录级别声明。
4M60100
<httpRuntime maxRequestLength="4096" executionTimeout="60" appRequestQueueLimit="100"/>
6 <pages>
<pages>可以在计算机、站点、应用程序和子目录级别声明。
)(
7<sessionState>
作用:为当前应用程序配置会话状态设置(如设置是否启用会话状态,会话状态保存位置)。
<sessionState mode="InProc" cookieless="true" timeout="20"/>
</sessionState>
mode="InProc"SAL
Cookie(False
表示:会话可以处于空闲状态的分钟数
8<trace>
ASP.NET 跟踪服务,主要用来程序测试判断哪里出错。
Web.config
<trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />
enabled="false"
(trace.axd) Web 服务器
Web.config
Web.config
1. <configSections> </configSections> .NET Framework
<configSections> 区域之后为声明的节做实际的配置设置。
<configuration>
<configSections>
<section name="appSettings" type="System.Configuration.NameValueFileSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</configSections>
<appSettings>
<add key="scon" value="server=a;database=northwind;uid=sa;pwd=123"/>
</appSettings>
<system.web>
......
</system.web>
</configuration>
Web.config ConfigurationSettings.AppSettings Web.config
二、web.config中的session配置详解
Web.config
< sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
cookieless="false"
timeout="20"
/>
SessionsessionState
< sessionState mode="Off|InProc|StateServer|SQLServer"
cookieless="true|false"
timeout="number of minutes"
stateConnectionString="tcpip=server:port"
sqlConnectionString="sql connection string"
stateNetworkTimeout="number of seconds"
/>
Session
Ø Off Session
SessionASP
Session
SessionSQL Server
Ø cookieless Session
Cookieless
Cookie
Session20
Session"tcpip=127.0.0.1:42424”modeStateServer
sqlConnectionString SQL Server"data source= localhost;Integrated Security=SSPI;Initial Catalog=northwind"mode SQLServer
stateNetworkTimeout StateServerSessionWebTCP/IP10
ASP.NETSession
SessionSessionSessionIDSessionASPSessionIDCookieCookieSession ASP.NETSessionCookieCookieless
ASP.NETCookieSessionCookielessSession
WebWeb.Config
< sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
cookieless="false"
timeout="20"
/>
cookieless="false"cookieless="true"Session CookieURLIEIEWeb
https://localhost/MyTestApplication/(ulqsek45heu3ic2a5zgdl245) /default.aspxSession IDIIS自动加上的,不会影响以前正常的连接。
ASP.NETSession
SessionState.aspx< body>< /body>
< scriptrunat="server">
Sub Session_Add(sender As Object, e As EventArgs)
Session("MySession") = text1.Value
span1.InnerHtml = "Session data updated! < P>Your session contains: < font color=red>" & Session("MySession"). ToString() & "< /font>"
End Sub
Sub CheckSession(sender As Object, eAs EventArgs)
If (Session("MySession")Is Nothing) Then
span1.InnerHtml = "NOTHING, SESSION DATA LOST!"
Else
span1.InnerHtml = "Your session contains: < font color= red>" & Session("MySession").ToString() & "< /font>"
End If
End Sub
< /script>
< formrunat="server">
< inputtype="text"runat="server"name="text1">
< inputtype="submit"runat="server"OnServerClick="Session_Add"
value="Add to Session State " name="Submit1">
< inputtype="submit"runat="server"OnServerClick="CheckSession"
value=" View Session State " name="Submit2">
< /form>
< hrsize="1">
< fontsize="6">< spanrunat="server" />< /font>
SessionState.aspxSession信息。
Session
Web.config
< sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
cookieless="false"
timeout="20"
/>
modeInProc
ASPSessionIISIISSessionIISIISSessionSQL ServerSessionASP.NET
SessionState.aspxSessionIISIISIIS(NT4IIS@#$%^&)SessionState.aspxSession信息,发现信息已经丢失了。
Session
->ASP.NET State ServiceSessionWindows-> aspnet_state.exeSession
Web.configmodeStateServerIE SessionState.aspxSessionIISSessionState.aspxSession
SessionSessionmodeStateServerstateConnectionString192.168.0.1SessionIP192.168.0.2 stateConnectionString="tcpip=192.168.0.2:42424"192.168.0.2.NET FrameworkASP.NET State Services服务。
SessionSQL Server
SQL ServerSQL ServerSQL Server InstallSqlState.sqlSQL ServerSessionSessionSQL Server
[system drive]/winnt/Microsoft.NET/Framework/[version]/
SQL ServerASPStateSessiontempdb ASPStateTempSessionsASPStateTempApplicationsASP Application->SQL Server->ASPState_Job_DeleteExpiredSessionsASPStateTempSessions Session
Web.configmodeSQLServersqlConnectionString
sqlConnectionString="data source=localhost; Integrated Security=SSPI;"
data sourceSQL ServerIPSQL ServerIIS127.0.0.1 Integrated Security=SSPIWindowsASP.NETuserid=sa;password=SQL ServerSQL ServerActive Directory
SessionState.aspxSessionSession SQL ServerSessionSessionSQL Server中的,能干什么就看你的发挥了。
SessionASP.NETASP
WebWindowsUnix IISApacheSQL ServerOracle强大,但是,谁可以将他们如此完美的联动到一起呢?所以说,虽然微软每一方面都不是太强,但是如果把微软的东西都整合到一起,谁敢说他不强大呢?微软就是微软!
三、Asp.net 关于form认证的一般设置
asp.net form
web.configform
<authentication mode="Forms">
<forms name="auth" loginUrl="index.aspx" timeout="30"></forms>
</authentication>
<authorization>
<deny users="?" />
</authorization>
2: ;
<configuration><system.web>,<system.web>..</system.web>;
---------------- userReg.aspx.
<location path="userReg.aspx">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
3 , ;
if()
System.Web.Security.FormsAuthentication.SetAuthCookie(, false);
四、访问Web.config文件
ConfigurationSettings.AppSettings Web.config 文件示例:获取上面例子中建立的连接字符串。例如:
最后更新:2017-04-02 00:06:29