配置 ASP.NET 身份验证方案,该方案用于识别查看 ASP.NET 应用程序的用户。
configuration 元素(常规设置架构)??system.web 元素(ASP.NET 设置架构)
????authentication 元素(ASP.NET 设置架构)
<authentication mode="[Windows|Forms|Passport|None]" > <forms>...</forms> <passport/> </authentication> |
属性和元素
下面几部分描述了属性、子元素和父元素。
属性
属性 | 说明 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
mode |
必选的属性。 指定应用程序的默认身份验证模式。此属性可以为下列值之一。
默认值为 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 属性指定身份验证方案。有关可用的身份验证方案的更多信息,请参见
默认配置
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 |
请参见
任务
参考
system.web 元素(ASP.NET 设置架构)authentication 的 forms 元素(ASP.NET 设置架构)
authentication 的 passport 元素(ASP.NET 设置架构)
configuration 元素(常规设置架构)
概念
其他资源
常规配置设置 (ASP.NET)
ASP.NET 配置设置