简体   繁体   English

授权属性和InitializeSimpleMembership

[英]Authorize attribute and InitializeSimpleMembership

I am new to MVC and this question might be a novice question. 我是MVC的新手,这个问题可能是新手问题。 I have seen examples about Authorize attribute on the web. 我在网上看到有关Authorize属性的示例。 In these examples the authors controller code looks like this 在这些示例中,作者的控制器代码如下所示

[Authorize]
[InitializeSimpleMembership]
Public class someController: Controller {...}

But if you check the AccountController you will find that 但是,如果您检查AccountController,您会发现

[Authorize]
[InitializeSimpleMembership]
Public class AccountController: Controller {...}

So my question is why does the author not simply use [Authorize] without initializing Simple membership in the someController since it will be initialized any way if it reaches Account Controller. 所以我的问题是为什么作者不简单地使用[Authorize]而不在someController初始化简单成员资格,因为一旦到达Account Controller,它将以任何方式进行初始化。

when you are using InitializeSimpleMembership attribute it means that you may not using membership in your application every where, so if you are not using membership you may don't want to waste resources for it, so the attribute initialize simple membership for application in run time, if you are sure that the application will use simple membership you can just add this line of code to application start in global.asax WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true); 当您使用InitializeSimpleMembership属性时,这意味着您可能不会在应用程序中的任何地方都使用成员身份,因此,如果您不使用成员身份,则可能不想为其浪费资源,因此该属性在运行时为应用程序初始化简单成员身份,如果您确定应用程序将使用简单的成员身份,则只需在global.asax WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true); and then get ride of InitializeSimpleMembership attribute every where, maybe author thinks that the membership don't have too many use cases, so decided to put the attribute in place, and maybe application use SomeController before calling any action of AccountController 然后随处使用InitializeSimpleMembership属性,也许作者认为该成员资格没有太多用例,因此决定放置该属性,并且在调用AccountController的任何操作之前,应用程序可能会使用SomeController

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM