简体   繁体   English

绕过控制器MVC上的Windows身份验证

[英]Bypass windows authentication on a controller MVC

I've enabled Windows authentication on my mvc web application but I need it to be bypassed on the first page(so anyone can access HomeController\\Index).How can this be achieved? 我在我的mvc Web应用程序上启用了Windows身份验证,但我需要在第一页上绕过它(所以任何人都可以访问HomeController \\ Index)。如何实现?

Here's my authentication logic: 这是我的身份验证逻辑:

<location path="~/DashboardController" />
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <authentication mode="Windows" />
    <authorization>
      <allow users="Domain\MyUserName"/>
      <deny users="*" />
    </authorization>
  </system.web>

I've tried decorating the default dashboard controller Action with [Authorize] and [Authorize(Users="*")] but when I try access the home page the browser displays a prompt to enter credentials 我尝试使用[Authorize][Authorize(Users="*")]装饰默认仪表板控制器操作但是当我尝试访问主页时,浏览器会显示输入凭据的提示

Add the [AllowAnonymous] attribute to your Index method [AllowAnonymous]属性添加到Index方法

[AllowAnonymous]
public ActionResult Index()
{
    ViewBag.Message = "Welcome to ASP.NET MVC!";

    return View();
}

Or if you don't want to use attributes for what ever reason you can allow this via the web.config. 或者,如果您不想使用属性,您可以通过web.config允许此操作。 (I'd avoid the web.config where possible and use attributes. See this blog from Jon Galloway for more info ) (我尽可能避免使用web.config并使用属性。 有关更多信息,请参阅Jon Galloway的这篇博客

<location path="HomeController/Index">
    <system.web>
        <authorization>
            <allow users="?" />
        </authorization>
    </system.web>
</location>

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

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