Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

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

like image 984
Denys Wessels Avatar asked Oct 17 '25 10:10

Denys Wessels


1 Answers

Add the [AllowAnonymous] attribute to your Index method

[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. (I'd avoid the web.config where possible and use attributes. See this blog from Jon Galloway for more info)

<location path="HomeController/Index">
    <system.web>
        <authorization>
            <allow users="?" />
        </authorization>
    </system.web>
</location>
like image 149
codingbadger Avatar answered Oct 20 '25 00:10

codingbadger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!