2

I am sure this is a basic answer, but my search powers are not helping me today. I have an ASP.NET MVC 2 (.NET 3.5) application. It is hosted on IIS 6.

For the sake of this question I have two urls.

http://example.com/

http://example.com/admin

I want admin to be available to any user on the domain, and the root to be available to all users. The server is on the domain but the domain is example1.com, so they are not the same.

Since this is ASP.NET MVC there is no Admin folder to set rights on. I have tried setting the whole site to block anonymous request and have had it allowing all request. Then in the web.config I set it up to deny unauthenticated users in the admin folder and/or allow anonymous access to the root.

What I end up getting is a login prompt that doesn't work. I've tried the user name and example1\username but it always fails to login.

What am I missing?

==== Clarification/Answer ==== Pandincus gave a great code suggestion, adding [Authorize] to the class is a very clean way to make this work. However my problem ended up being the fact that I was doing all of this on the same box. I had a HOSTS entry for example.com on my box and was hitting it via the URL. When I put a HOSTS entry on my other box and hit the site it allowed me to log in without issue. My question was slightly incomplete as I should have mentioned this and the fact that http://localhost/ was working just fine.

1 Answer 1

4

Don't use the web.config to set access. Thats how you would do it in asp.net web forms.

  1. Configure your web.config to use windows authentication.
  2. Use an [Authorize] attribute on any admin controller you have.

Any controllers without an [Authorize] attribute should be open to the public automatically. So, only put your attribute on the controllers you want to lock down.

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

2 Comments

OK, headed to search.... but as I do that. How can I make this not do anything on my box? My box is IIS 7.5 and it doesn't play as nice with this (from what I can tell).
Never mind, actually makes it behave better on my box as well! Your answer didn't fully address my problem, but it did give me a better code solution so I'll be giving you the answer and expanding in my question, for future coders.

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.