Anders
Anders

Reputation: 12560

Log in loop ASP.NET MVC view with Authorize attribute

I just uploaded an MVC application to my live server. Before doing so, I created a user ('anders') after creating the necessary tables and stored procedures for authentication via the aspnet_regsql command in the VS2008 Command Prompt. I successfully tested, locally, that I need to log in before (or while) accessing this view:

[Authorize(Roles = "admin")]
public ViewResult Index()
{
    return View();
}

I made a back up of my local database, and restored this to my live server. Before testing the view, I verified that I can log in with my newly-created user. However, when I try to access the view after logging in, I get redirected indefinitely to the log in page.

New Info

Looks like something else is going on, but the above information may still be useful. Apparently my user is not in the admin group, even though I looked into the database and verified that my UserID is in the dbo.aspnet_Roles table and the RoleID corresponds with the admin role. I found this out by changing the code at the top of the master page where it welcomes the logged in user, and noticed that it returned false:

Welcome <b><%= Html.Encode(Page.User.Identity.Name) %></b>!
(<%= Html.Encode(Page.User.IsInRole("admin")) %>)

Both my user and the newly created 'stackoverflow' (password is passw0rd, for you guys to check it out) user are supposed to be in the admin role, but for some reason they are not.

Any help with tracking down the reason why my users aren't being recognized as being in the 'admin' role would be greatly appreciated. Thanks in advance!

Link to my live server.

Upvotes: 0

Views: 1102

Answers (2)

ppvi
ppvi

Reputation:

I was having the same Issue. In web.config:

<roleManager enabled="true">
...

Was set to false at server's config but not local's.

Upvotes: 0

Ahmed Khalaf
Ahmed Khalaf

Reputation: 1220

Are you using any caching technique ? this maybe the reason.

also you need to verify that the RoleProvider is working, but without more details I cant help more

Upvotes: 1

Related Questions