authentication 元素(ASP.NET 设置架构)
[本文档仅供预览,在以后的发行版中可能会发生更改。包含的空白主题用作占位符。]
配置 ASP.NET 身份验证方案,该方案用于识别查看 ASP.NET 应用程序的用户。
<authentication
mode="[Windows|Forms|Passport|None]"
>
<forms>...</forms>
<passport/>
</authentication>
特性和元素
以下几节描述了特性、子元素和父元素。
特性
特性 |
说明 |
---|---|
mode |
必需的特性。 指定应用程序的默认身份验证模式。 此特性可以为下列值之一。
值说明
Windows 将 Windows 验证指定为默认的身份验证模式。将它与以下任意形式的 Microsoft Internet 信息服务 (IIS) 身份验证结合起来使用:基本、摘要、集成 Windows 身份验证 (NTLM/Kerberos) 或证书。在这种情况下,您的应用程序将身份验证责任委托给基础 IIS。
Forms 将 ASP.NET 基于窗体的身份验证指定为默认身份验证模式。
Passport 将 Microsoft Passport Network 身份验证指定为默认身份验证模式。
None 不指定身份验证。您的应用程序仅期待匿名用户,否则它将提供自己的身份验证。
默认值为 Windows。 |
子元素
元素 |
说明 |
---|---|
forms |
配置 ASP.NET 应用程序以执行基于窗体的自定义身份验证。 |
passport |
指定要重定向到的页(如果该页要求身份验证,而用户尚未通过 Microsoft Passport Network 身份验证注册)。 |
父元素
元素 |
说明 |
---|---|
configuration |
指定公共语言运行时和 .NET Framework 应用程序所使用的每个配置文件中均需要的根元素。 |
system.web |
指定配置文件中 ASP.NET 配置设置的根元素,并包含用于配置 ASP.NET Web 应用程序和控制应用程序行为方式的配置元素。 |
备注
authentication 元素为 ASP.NET 应用程序配置 ASP.NET 身份验证方案。 身份验证方案确定如何识别要查看 ASP.NET 应用程序的用户。 mode 特性指定身份验证方案。 有关可用的身份验证方案的更多信息,请参见 ASP.NET Authentication。
默认配置
Machine.config 或根 Web.config 文件中未显式配置下面的默认 authentication 元素。 但它是 .NET Framework 2.0 版中应用程序返回的默认配置。
<authentication mode="Windows">
<forms
name=".ASPXAUTH"
loginUrl="login.aspx"
defaultUrl="default.aspx"
protection="All"
timeout="30"
path="/"
requireSSL="false"
slidingExpiration="true"
cookieless="UseDeviceProfile" domain=""
enableCrossAppRedirects="false">
<credentials passwordFormat="SHA1" />
</forms>
<passport redirectUrl="internal" />
</authentication>
下面的默认 authentication 元素在 .NET Framework 1.1 版的 Machine.config 文件中配置。
<authentication mode="Windows">
<forms
name=".ASPXAUTH"
loginUrl="login.aspx"
protection="All"
timeout="30"
path="/"
requireSSL="false"
slidingExpiration="true">
<credentials passwordFormat="SHA1"></credentials>
</forms>
<passport redirectUrl="internal" />
</authentication>
下面的默认 authentication 元素在 .NET Framework 1.0 版的 Machine.config 文件中配置。
<authentication mode="Windows">
<forms
name=".ASPXAUTH"
loginUrl="login.aspx"
protection="All"
timeout="30"
path="/" >
<credentials passwordFormat="SHA1"></credentials>
</forms>
<passport redirectUrl="internal" />
</authentication>
示例
下面的代码示例演示如何为基于窗体的身份验证配置站点、指定传输来自客户端的登录信息的 Cookie 的名称以及指定当初始身份验证失败时使用的登录页的名称。 必须将 authorization 节包含在内才能要求对所有用户进行 Forms 身份验证,并拒绝匿名用户访问站点。
<configuration>
<system.web>
<authentication mode="Forms">
<forms name="401kApp" loginUrl="/login.aspx"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</configuration>
元素信息
配置节处理程序 |
|
配置成员 |
|
可配置的位置 |
Machine.config 根级别的 Web.config 应用程序级别的 Web.config |
要求 |
Microsoft Internet 信息服务 (IIS) 版本 5.0、5.1 或 6.0 .NET Framework 版本 1.0、1.1 或 2.0 Microsoft Visual Studio 2003 或 Visual Studio 2005 |
请参见
任务
How to: Configure Specific Folders Using Location Settings
How to: Lock ASP.NET Configuration Settings
参考
authentication 的 forms 元素(ASP.NET 设置架构)
authentication 的 passport 元素(ASP.NET 设置架构)
概念
ASP.NET Configuration File Hierarchy