InitializeSimpleMembership过滤器问题 [英] InitializeSimpleMembership filter issue

查看:129
本文介绍了InitializeSimpleMembership过滤器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有MVC 4应用程序,它具有开箱即用的简单成员资格机制.最近,我发现,每当我在InitializeSimpleMembershipAttribute过滤器中调用应用程序中的任何控制器时,就会执行OnActionExecuting方法!即使我已经注释掉Account控制器上的InitializeSimpleMembership属性,如下所示:

I have MVC 4 application with out of the box Simple Membership mechanism implemented. Recently I have discovered that every single time I call any of the controllers in my application OnActionExecuting method in InitializeSimpleMembershipAttribute filter is executed! Even though I have commented out InitializeSimpleMembership attribute on Account controller like so:

[Authorize]
//[InitializeSimpleMembership]
public class AccountController : Controller
{

过滤器仍在调用!这个电话从哪里来?

the filter is still getting called! Where is this call coming from?

推荐答案

我通常会默认删除Filters文件夹中的InitializeSimpleMembership文件.您希望它在启动时初始化一次,所以最好的选择是Global.asax

I would usually delete the InitializeSimpleMembership file which is in the Filters folder by default. You want it to initialize once at start up so the best place for that is Global.asax

现在要在Global.asax中保持application_start()方法的结构一致,我将其添加到该方法调用的配置文件中.您可以创建一个新的,但是我通常只会将其添加到AuthConfig中. AuthConfig具有默认的OAuth代码,因此将所有身份验证方法保持在一起是很有意义的.

Now to keep the structure of the application_start() method consistent in Global.asax, I would add it to a config file being called by that method. You could create a new one but I would usually just add it to AuthConfig. AuthConfig has the default OAuth code, so it makes sense to keep all the authentication methods together.

启动时,global.asax会调用一次名为RegisterAuth的方法.只需添加

The Method in called RegisterAuth is called by global.asax once at start up. Just add

//Local Authentication
            WebSecurity.InitializeDatabaseConnection("MyDbConnection", "UserProfile", "UserId", "UserName", autoCreateTables: false);

您将在构建时遇到一些错误,这些错误可以通过使用引用过滤器文件夹的语句删除(也许仅在具有重新共享功能的情况下)并删除InitializeSimpleMembership属性(不再需要)来解决.

You will have a few errors on build which are resolved by removing using statements referencing the filters folder (maybe only if you have resharper) and removing the InitializeSimpleMembership attribute (it is no longer needed).

在我的示例中,由于我在解决方案中使用数据库项目,因此autoCreateTables为false.如果您使用其他方法(例如代码优先),则可能希望该方法为真

In my example I have autoCreateTables to false as I use a Database project in my solution. If you use another method such as code-first you may want that to true

这篇关于InitializeSimpleMembership过滤器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆