ASP.Net MVC授权操作过滤器

我想了解在MVC预览4中使用授权[授权]动作过滤器时错误处理的工作原理.

我有一个这样的动作:

[Authorize(Roles = "DOMAIN\\NOTAUTHORISED_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.

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....