ich ein einfache für mein MVC-Projekt IIdentity
und IPrincipal
entwickelt habe, und ich würde den Wert mit der richtigen Artdie IIdentity Eigenschaft von Benutzern außer Kraft setzt
Hier ist meine individuelle Identität außer Kraft zu setzen wie die User
und User.Identity
zurückzukehren:
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; }
}
Hier sind meine individuellen Auftraggeber:
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
}
Hier ist meine Gewohnheit Controller, ich habe die User
Eigenschaft erfolgreich aktualisiert meinen benutzerdefinierten Haupttyp zurück:
public abstract class BaseController : Controller
{
protected new virtual MyPrincipal User
{
get { return HttpContext == null ? null : HttpContext.User as MyPrincipal; }
}
}
Wie kann ich es tun die gleiche Art und Weise für User.Identity
meine individuelle Identität Typ zurückzukehren?
wo setzen Sie Ihren benutzerdefinierten Prinzipal auf HttpContext? –
In meiner global.asax.cs Application_AuthenticateRequest-Methode – Swell