MVC 3 Authorize attribute not working in action method

In my web application I want to add authorization in certain action method in controller not on the whole controller. I added the following

  [Authorize]
  public ActionResult ManageResturant(long Id = 0)
  {
  }

and in web.config i added

<authentication mode="Forms" >
  <forms loginUrl="~/Auth/LogIn"/>
</authentication>

but when i go to that action method the page loads normally which is wrong i want the page to redirect to the login page

any suggestions?

Answers


Thanks John for your comment i really found the solution after your hint the problem was in my code

I use a session to store the logged in user with the use of FormsAuthentication to make sure all users are login to make the login link appears to them

the problem was when session expires the FormsAuthentication still validating the user as a logged in user so it appears that the user is logged out but in fact he is logged in using form authentication

so what i did OnActionExecuting method i make a check on session if its null i do logout for the user so in this case i make sure that the user is logged out


Settings looks ok, are you really sure that you are calling this Action? DonĀ“t you have some another Action with name ManageResturant without [Authorize] annotation?


Need Your Help

Edit Row Details in Form - PHP MySQL

php html mysql sql sql-update

This is the first time I've tried editing data already in my database. I go through and edit any value and submit, no errors, but the data is not updating when I look at the table. Here is the page...

In Django ORM, A "Student - Course" Model design

database django django-models django-views pinax

I would like to design a model for an online private school in Django. It focuses on relation among Students, Tutors and Courses.