ASP.NET MVC 4 Applying Windows Authentication to a Single Controller?

I have an MVC 4 application that is accessible to all users, without having to log in. There is only one controller that must use Windows Authentication through Web.Config, for example:

<authentication mode="Windows" /> <authorization> <allow users="domain\jsmith" /> <deny users="*" /> </authorization> 

The controller will MySite.Com/MyApp/MyAdminReportController

If possible, how?

+4
source share
1 answer

I think you just need Windows auth and specify paths that only require authorization. If you don't need auth forms either, it looks like this:

 <configuration> ... <system.web> ...... <authentication mode="Windows"> </authentication> </system.web> <location path="MyAdminReport"> <system.web> <authorization> <deny users="?" /> </authorization> </system.web> </location> </configuration> 

This is an approach to web configuration, other options add the [Authorize] attribute to your controllers (even if not a hole controller, you can add this attr only for certain actions).

 [Authorize] public class MyAdminReportController : Controller { //[Authorize] public ActionResult PrivatePage() { return View(); } } 
+5
source

All Articles