3
我上了一個新的應用程序工作的強制執行ClaimType和正在使用ASP.NET身份,想知道是否有強制執行特定的聲明類型存在於ClaimsIdentity的方式。以下是我迄今爲止..它的工作原理,但它似乎有這個東西會應建/在,也許我只是沒有找到它。上ClaimsIdentity
public void SignIn(IUserIdentity user, string authenticationType, bool isPersistent)
{
if (user == null)
{
string msg = "UserIdentity or UserIdentity is null";
_logger.Error(msg);
throw new NullReferenceException(msg);
}
List<Claim> claims = _claimService.GetClaims(user.UserId);
var identity = new ClaimsIdentity(claims, authenticationType, ClaimTypes.Name, ClaimTypes.Role);
if (claims.Any() && claims.Single(c => c.Type == ClaimTypes.Name).Value != null)
{
_owinContext.Authentication.SignIn(new AuthenticationProperties
{
IsPersistent = isPersistent
}, identity);
}
else
{
throw new SecurityException("Invalid or null Name Claim");
}
}
高興知道我不是完全堅果和缺少的東西。我完全,幾乎逐字地回答你的答案......太有趣了。 – DfwForSale
這不工作的偉大,但我並不需要檢查每個請求,是的,這是一個全球性的屬性,似乎有點矯枉過正。我只需要聲明我有一個名稱標識符。 – DfwForSale
嗯... OK。我會盡量在明天提出一個更好的解決方案。我需要「冬眠」瞬間,因爲它是過去的午夜在這裏。 – LostInComputer