Authenticating bypass windows on MVC controller

I have enabled windows authentication in my mvc web app, but I need it to be bypassed on the first page (so anyone can access the 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 tried to decorate the default dashboard controller with [Authorize]

and [Authorize(Users="*")]

, but when I try to open the home page, the browser displays a prompt for credentials

+3


source to share


1 answer


Add attribute [AllowAnonymous]

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 whatever reason, you can enable it via web.config. (I would avoid web.config where possible and use attributes. See this blog by Jon Galloway for more information )

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

      

+2


source







All Articles