C# 具有Windows身份验证的SessionAuthenticationModule
我正在使用Windows身份验证,因为我的ASP.NET MVC 5应用程序正在内部网中运行(Active Directory是主要的身份验证颁发者) 由于广告和浏览器在每次请求时都会不断地进行401握手,所以网站的速度相当慢 我现在正在研究一种缓存从AD收到的声明的方法,以便获得一些性能增益 这在WIF和SessionAuthenticationModule中可行吗?一旦生成SessionSecurityToken,它会停止对AD的后续请求吗?在ASP.NET管道中创建这样一个令牌的最佳位置是什么C# 具有Windows身份验证的SessionAuthenticationModule,c#,asp.net,asp.net-mvc,wif,claims-based-identity,C#,Asp.net,Asp.net Mvc,Wif,Claims Based Identity,我正在使用Windows身份验证,因为我的ASP.NET MVC 5应用程序正在内部网中运行(Active Directory是主要的身份验证颁发者) 由于广告和浏览器在每次请求时都会不断地进行401握手,所以网站的速度相当慢 我现在正在研究一种缓存从AD收到的声明的方法,以便获得一些性能增益 这在WIF和SessionAuthenticationModule中可行吗?一旦生成SessionSecurityToken,它会停止对AD的后续请求吗?在ASP.NET管道中创建这样一个令牌的最佳位置是
你应该做的是
public class AdClaimsAppender : ClaimsAuthenticationManager
{
public override ClaimsPrincipal Authenticate(string resourceName, ClaimsPrincipal incomingPrincipal)
{
if (!incomingPrincipal.Identity.IsAuthenticated)
{
return base.Authenticate(resourceName, incomingPrincipal);
}
var adClaims = GetExtraAdClaims(incomingPrincipal);
var newClaimsIdentity = new ClaimsIdentity(adClaims, "Windows");
var newClaimsPrincipal = new ClaimsPrincipal(newClaimsIdentity);
return base.Authenticate(resourceName, newClaimsPrincipal);
}
}
} <system.webServer>
<modules>
<add name="SessionAuthenticationModule"
type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler"/>
</modules>
</system.webServer>
将AdClaimsAppender挂接在何处?e.FederationConfiguration.IdentityConfiguration.ClaimsAuthenticationManager=new AdClaimsAppender();当我第一次读到你的答案时,我有了希望。但是,唉,这对我也不起作用。
using System.IdentityModel.Services;
using System.IdentityModel.Services.Configuration;
public class MvcApplication : HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
FederatedAuthentication.FederationConfigurationCreated += FederatedAuthentication_FederationConfigurationCreated;
}
private static void FederatedAuthentication_FederationConfigurationCreated(object sender, FederationConfigurationCreatedEventArgs e)
{
//from appsettings...
const string domain = "";
const bool requireSsl = false;
const string authCookieName = "YourSiteAuth"; //default is fedauth, i normally create my own name as it is easier to identify when you have a lot of cookies.
e.FederationConfiguration.CookieHandler = new ChunkedCookieHandler
{
Domain = domain,
Name = authCookieName,
RequireSsl = requireSsl,
PersistentSessionLifetime = new TimeSpan(0, 0, 30, 0)
};
}