加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

ASP.Net MVC授权操作过滤器

发布时间:2020-12-15 20:09:34 所属栏目:asp.Net 来源:网络整理
导读:我想了解在MVC预览4中使用授权[授权]动作过滤器时错误处理的工作原理. 我有一个这样的动作: [Authorize(Roles = "DOMAINNOTAUTHORISED_ROLE" )][HandleError]public ActionResult NeedAuthorisation(){ throw new NotImplementedException();} 当我访问ur
我想了解在MVC预览4中使用授权[授权]动作过滤器时错误处理的工作原理.

我有一个这样的动作:

[Authorize(Roles = "DOMAINNOTAUTHORISED_ROLE" )]
[HandleError]
public ActionResult NeedAuthorisation()
{
    throw new NotImplementedException();
}

当我访问url:http:// localhost:2197 / testAuthorisation / NeedAuthorisation,我在浏览器中找到一个空白页.在Firebug中,我可以看到已经发出请求,并且返回了401 – 未经授权的响应状态.但是我没有被重定向或返回一个customError.当使用我被授权的角色时,一切都会按预期工作.

这是使用Windows身份验证.我正在编写一些代码来尝试Forms身份验证,看看我是否遇到同样的问题.
我有< customerrors mode =“On”/>在testAuthorization文件夹和Shared文件夹中设置并创建错误页面.

解决方法

我最终找到了解决我的问题的 this MVC tutorial:

Exactly what happens when you attempt to invoke a controller action without being the right permissions depends on the type of authentication enabled. By default,when using the ASP.NET Development Server,you simply get a blank page. The page is served with a 401 Not Authorized HTTP Response Status.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读