right way to have role based custom auth query database on every request asp.net mvc

前端 未结 2 1759
别跟我提以往
别跟我提以往 2021-01-14 07:24

This may be a slightly ignorant question but Im new to mvc so Im sorry!

I studied the nerd dinner auth model but In my app I have a complicated role based authentica

相关标签:
2条回答
  • 2021-01-14 08:02

    "Correct?" Its a matter of opinion.

    I'd say, if you aren't experiencing issues with the database performance caused by this query, then don't worry about it.

    If you are, you can centralize your authentication code into some sort of auth provider or type, and cache authentication information in memory until a write updates the database, which should invalidate the cache at the same time.

    (Your second question would do well on its own; I don't have enough info to answer it.)

    0 讨论(0)
  • 2021-01-14 08:14

    An alternative approach is to store your user's roles in the authentication ticket when your user is authenticated. Then for every request (Application_AuthenticateRequest method of the global.asax file) you can extract the roles from the authentication ticket and create a GenericPrincipal.

    See this answer for more details.

    0 讨论(0)
提交回复
热议问题