问题描述
我觉得我对理解 SimpleMembershipProvider
几乎是60%,其余是了解如何在内部工作。
I think my understanding on SimpleMembershipProvider
is almost 60% and the rest is getting to know how it internally work.
您可以使用 [InitializeSimpleMembership]
过滤只有在的AccountController(默认模板)时,迅速发现了一些问题。我觉得在任何地方使用Memberhsip API或 WebMatrix.WebSecurity
,你需要确保这个过滤器应首先被调用。
You can quickly found some issue when using [InitializeSimpleMembership]
filter only in AccountController (the default template). I think anywhere you use Memberhsip API or WebMatrix.WebSecurity
, you need to make sure this filter should be called first.
之后,如果你在我的 _Layout.cshtml
使用 User.IsInRole
。您需要将过滤器应用到所有控制器,然后你开始在全球范围内注册它。
Later, If you use User.IsInRole
in my _Layout.cshtml
. You need to apply the filter to all controllers, then you start registering it in globally.
不过,我只是知道有 LazyInitializer.EnsureInitialized
这使得每个应用开始只执行一次初始化。
However I just realize there is LazyInitializer.EnsureInitialized
which make the initialization performed only once per app start.
那么,为什么 SimpleMembershipInitializer
(在过滤器)不是直接的Application_Start?
没有任何理由使用的过滤器?
So why the SimpleMembershipInitializer
(in the filter) is not directly in Application_Start?Is there any reason to use the filter?
推荐答案
我相信模板用于数据库初始化属性,因此如果初始化失败,该网站的未经验证的部分仍然会正常工作。
I believe the template used an attribute for database initialization so that the non-authenticated portions of the site would still work if the initialization failed.
有关最实用的目的,最好只是在App_Start这件事。
For most practical purposes, it's best to just have this done in the App_Start.
这篇关于为什么InitializeSimpleMembershipAttribute在MVC 4应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!