简体   繁体   中英

ASP.NET MVC2 Windows Authentication on Specific Controllers

In ASP.NET MVC2 how do I configure a site such that by default no authentication is required, but on one particular controller I do want Windows Authentication.

Edit: I don't think this is possible based on my testing.

[Authorize]
public class MyController : Controller
{
  public ActionResult Index()
  {
    return View();
  }
}

will require authorization for all actions on MyController , but anything that doesn't have the [Authorize] attribute should then be publically accessible.

You'll also need to set the Windows authentication in web.config.

<authentication mode="Windows"/>

This link may be helpful.

Edit

The only time it should be necessary to create a separate application is if you need to use both Windows and forms authentication within the same site - for instance, if you needed forms authentication for users to hit, say, a discussion forum, but windows authentication for an admin area. Since the authentication method is set at the application level and can't be overridden, in this case the parts of the app that require windows authentication would have to be split into a separate web app and virtual directory in IIS.

I do not think this is possible since you need to set windows auth at the site level in IIS. You will need two separate web apps for this functionality.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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