我試圖找出哪裏是ASP.NET MVC3基礎架構中的最佳擴展點,以便在接收到聲明身份驗證之後映射自定義用戶信息(從本地數據庫加載)從Azure的AccessControl的服務2.0Asp.net MVC - 映射要求自定義用戶身份的身份
我試圖通過覆蓋Microsoft.IdentityModel.Claims.ClaimsAuthenticationManager類的身份驗證方法來實現這一點:
public class ClaimsTransformationModule : ClaimsAuthenticationManager
{
public override IClaimsPrincipal Authenticate(string resourceName, IClaimsPrincipal incomingPrincipal)
{
// Load User from database and map it to HttpContext
// Code here
return base.Authenticate(resourceName, incomingPrincipal);
}
}
然而,似乎這個方法是在調用一次以上頁面加載請求。 在此處加載自定義用戶信息可能會產生性能問題。 我想每個認證會話只加載一次。
有沒有更好的地方做到這一點? 也許某處IClaimsPrincipal構建的較低級別?
簡單而高效。非常感謝:) –
把一個調試標記放在那個if語句裏,你會看到它不止一次運行。 –
雖然這可行,但它會針對每個請求運行 – Rui