I opracowali prosty IIdentity
i IPrincipal
dla mojego projektu MVC i chciałbym zastąpić User
i User.Identity
aby zwrócić wartość z prawej TypZastąp właściwość IIdentity użytkownika
Oto mój zwyczaj Tożsamość:
public class MyIdentity : IIdentity
{
public MyIdentity(string name, string authenticationType, bool isAuthenticated, Guid userId)
{
Name = name;
AuthenticationType = authenticationType;
IsAuthenticated = isAuthenticated;
UserId = userId;
}
#region IIdentity
public string Name { get; private set; }
public string AuthenticationType { get; private set; }
public bool IsAuthenticated { get; private set; }
#endregion
public Guid UserId { get; private set; }
}
Oto mój zwyczaj Zleceniodawca:
public class MyPrincipal : IPrincipal
{
public MyPrincipal(IIdentity identity)
{
Identity = identity;
}
#region IPrincipal
public bool IsInRole(string role)
{
throw new NotImplementedException();
}
public IIdentity Identity { get; private set; }
#endregion
}
Oto mój zwyczaj Kontroler, pomyślnie zaktualizowana właściwość User
powrotu mojego niestandardowy typ Zleceniodawca:
public abstract class BaseController : Controller
{
protected new virtual MyPrincipal User
{
get { return HttpContext == null ? null : HttpContext.User as MyPrincipal; }
}
}
jaki sposób można zrobić to w taki sam sposób dla User.Identity
powrót mojego niestandardowy typ tożsamości?
gdzie ustawiasz niestandardową zlecenie na HttpContext? –
W mojej global.asax.cs Application_AuthenticateRequest metoda – Swell