窗体身份验证和放大器;授权MVC 4 [英] Forms Authentication & authorization MVC 4

查看:121
本文介绍了窗体身份验证和放大器;授权MVC 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图以acheive形式验证方法来创建一个匿名控制器。我配置我的IIS 7匿名的形式认证的启用并我的web.config设置为拒绝匿名用户。在登录控制器我把[使用AllowAnonymous]装修我的控制器(和我的动作)上。

I'm trying to create an anonymous controller in order to acheive form authentication. I configured my IIS 7 with anonymous and form authentication enabled and set my web.config to deny anonymous users. On the login controller I put the [AllowAnonymous] decoration on my controller (and my actions).

唯一的行动,我可以得到这套配置是登录操作(返回登录视图),和我猜的MVC允许,因为我将其设置为登录网址我得到这个动作在我的web.config。

The only action I can get on this set of configuration is the login action (which returns the "login" view), and I'm guessing that the MVC allows me to get this action because I set it as the login URL on my web.config.

下面是我的web配置的配置:

Here is my web config configuration:

     <authentication mode="Forms">
        <forms loginUrl="~/Login/Login" timeout="2880" />
     </authentication>

所有其他操作重定向到登录的动作。这套配置我不能达到像恢复密码,注册等其他重要的行动。

All the other actions are redirected to the login action. On this set of configuration I can't achieve other important actions like restore password, register, etc.

我在做什么错了?

推荐答案

自定义的行为,而不是授权的配置在web.config中(最好的MVC)使用全局鉴别过滤器

Use global authentification filter with custom behaviour instead of authorization configuration in web.config (best for MVC)

添加全局过滤器

public class FilterConfig
{
    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        filters.Add(new AuthorizeAttribute());
    }
}

然后,[使用AllowAnonymous]将作品及其他所有控制器和操作要求授权。

Then, [AllowAnonymous] will works, and all other controllers and actions requires Authorization.

这篇关于窗体身份验证和放大器;授权MVC 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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