1

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.

2 Answers 2

3
[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.

Sign up to request clarification or add additional context in comments.

8 Comments

I actually tried that but when I change my web.config to use Windows authentication it prompts me to log in on all requests (even those without [Authorize]). Is there any way to scope the authentication to a particular route or something?
You can't do it by route... hmmm. There's a deny=... attribute in web config that's probably necessary. let me look.
Can't you put the [Authorize] attribute on the Action (instead of the controller)? Or is that MVC3 only?
You can put it on either the controller or the action, but the question was about securing the entire controller. You can also put it on a base controller class, and anything that inherits from that class will require authorization.
@CaffeineFueled did you go through the steps in the link I posted? It seems to be working for me here.
|
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.