配置ASP.NET身份验证时,将身份验证模式设置为Windows
但具有子forms
元素时应采取的行为是什么?例如,以下配置为默认in MSDN:
<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>
但是我看到没有关于这里发生的事情的文件。子forms
元素的所有文档都假定身份验证模式为Forms
。特别奇怪的是,这是没有记录的,因为这是默认值。那么为什么Windows
身份验证模式具有forms
子元素?是否会忽略子元素,如果您将模式切换为Forms
,或者它是否会执行更多操作,那么它就是您可能想要的示例?
答案 0 :(得分:1)
我认为这仅仅是为了一个例子。我不能指向任何文档,但查看代码,只有当身份验证模式为表单时,表单设置才会被读取。
以下是FormsAuthenticationModule.cs
public void Init(HttpApplication app) {
// authentication is an app level setting only
// so we can read app config early on in an attempt to try and
// skip wiring up event delegates
if (!_fAuthChecked) {
_fAuthRequired = (AuthenticationConfig.Mode == AuthenticationMode.Forms);
_fAuthChecked = true;
}
if (_fAuthRequired) {
// initialize if mode is forms auth
FormsAuthentication.Initialize();
app.AuthenticateRequest += new EventHandler(this.OnEnter);
app.EndRequest += new EventHandler(this.OnLeave);
}
}
请注意,仅当模式是表单时才会调用 FormsAuthentication.Initialize ,其中表单从web.config文件设置。
代码来自FormsAuthenciation.cs文件
///
/// Initializes FormsAuthentication by reading
/// configuration and getting the cookie values and encryption keys for the given
/// application.
///
public static void Initialize() {
if (_Initialized)
return;
lock(_lockObject) {
if (_Initialized)
return;
AuthenticationSection settings = RuntimeConfig.GetAppConfig().Authentication;
settings.ValidateAuthenticationMode();
_FormsName = settings.Forms.Name;
_RequireSSL = settings.Forms.RequireSSL;
_SlidingExpiration = settings.Forms.SlidingExpiration;
if (_FormsName == null)
_FormsName = CONFIG_DEFAULT_COOKIE;
_Protection = settings.Forms.Protection;
_Timeout = (int) settings.Forms.Timeout.TotalMinutes;
_FormsCookiePath = settings.Forms.Path;
_LoginUrl = settings.Forms.LoginUrl;
if (_LoginUrl == null)
_LoginUrl = "login.aspx";
_DefaultUrl = settings.Forms.DefaultUrl;
if (_DefaultUrl == null)
_DefaultUrl = "default.aspx";
_CookieMode = settings.Forms.Cookieless;
_CookieDomain = settings.Forms.Domain;
_EnableCrossAppRedirects = settings.Forms.EnableCrossAppRedirects;
_TicketCompatibilityMode = settings.Forms.TicketCompatibilityMode;
_Initialized = true;
}
}