简体   繁体   English

ASP.net MVC-使用Windows身份验证/角色提供程序授权

[英]ASP.net MVC - Authorize with Windows Authentication/Role Provider

I am using Windows Authentication in my MVC application with the WindowsTokenRoleProvider. 我在WindowsTokenRoleProvider的MVC应用程序中使用Windows身份验证。 I created a controller action that looks like: 我创建了一个控制器动作,如下所示:

[Authorize(Roles=@"Fake\Role")]
public ActionResult Admin()
{
    return View();
}

When I try and hit this page I see a blank page. 当我尝试点击此页面时,我会看到一个空白页面。 Is there a way for me to display a custom view that says "You are not authorized to view this page" isntead of just showing a blank page. 有没有一种方法可以让我显示一个自定义视图,该视图显示“您无权查看此页面”,而只是显示一个空白页面。 If I was using forms authentication then it would redirect me to the login page, but that doesn't really make sense for Windows Authentication since you never really log in specifically. 如果我使用的是表单身份验证,那么它将把我重定向到登录页面,但这对Windows身份验证来说确实没有意义,因为您从未真正登录过。

You most likely are not getting a blank page (I'm not absolutely certain). 您很可能没有得到空白页(我不确定)。 You are most likely getting a http response that has no content, but has a 403 not authorized status code. 您很可能会收到一个http响应,该响应不包含任何内容,但是具有403未经授权的状态代码。

Assuming this is accurate, all you need to do is setup in ASP.NET custom errors (and IIS custom errors) is a redirect rule for 403 codes to the appropriate page. 假设这是正确的,您要做的就是在ASP.NET自定义错误(和IIS自定义错误)中进行设置,这是将403代码重定向到相应页面的规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM