How can I make accessing my custom IPrincipal easier in ASP.NET MVC?

前端 未结 6 1247
失恋的感觉
失恋的感觉 2021-02-14 23:18

I\'ve written a custom principal object which contains a few additional fields (email and userid in addition to the username).

In order to access these properties I have

6条回答
  •  长情又很酷
    2021-02-15 00:17

    When not authorized, you could set the user object to a specific instance of the custom principal with default values:

    if (authCookie == null)
    {
        context.User = CustomPrincipal.Default; // Or CreateDefault()
        return;
    }
    

提交回复
热议问题