Entering the loop View ASP.NET MVC with the Authorize attribute

I just downloaded the MVC application to my live server. Before doing this, I created the user ("anders") after creating the necessary tables and stored procedures for authentication using the aspnet_regsql command on the VS2008 command line. I successfully tested locally that I need to be logged in before (or for now) access to this view:

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

I made a backup of my local database and restored it to my real server. Before testing the view, I confirmed that I can log in with my newly created user. However, when I try to access the view after logging in, I am redirected to the login page indefinitely.

New information

Something else seems to be happening, but the above information may be helpful. Apparently, my user is not in the administrator group, although I looked in the database and confirmed that my UserID is in the dbo.aspnet_Roles table, and RoleID corresponds to the administrator role. I found this by changing the code at the top of the main page, where it greets the registered user and noticed that it returns false:

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

Both my user and the recently created "stackoverflow" (passw0rd password, for you guys to verify this), the user must be in the administrator role, but for some reason this is not so.

Any help in tracking down the reasons why my users are not recognized as "admin" is appreciated. Thanks in advance!

Link to my live server .

0
authentication asp.net-mvc
Sep 24 '09 at 15:39
source share
2 answers

Do you use any caching technique? this may be the reason.

also need to check if RoleProvider works, but without any details I can no longer help

+1
Sep 24 '09 at 15:46
source share

I had the same problem. In web.config:

 <roleManager enabled="true"> ... 

Set to false in the server configuration, but not locally.

0
Oct 19 '09 at 15:54
source share



All Articles