8

I have separated the Models into Specific project

After that MVC default [Authorize] attribute not working in my application

When i try to login the application it is not login the application nor it is redirecting to the specific page

tereško
  • 58,060
  • 25
  • 98
  • 150
Arul Prasanth
  • 147
  • 2
  • 2
  • 7
  • 4
    Could you post some code. Kind of hard to figure out what is wrong without it. – Gjohn Oct 14 '14 at 13:45
  • When place authorize attribute in before controller it simply do nothing when i remove attribute i correctly redirect me to the specific view i facing this after restructuring the solution separating Model from the main project into a separate project – Arul Prasanth Oct 14 '14 at 16:00

7 Answers7

16

Check if you have removed the forms authorization module. Some of the new templates remove forms authorization by default. If it has been removed, comment it out. It will look like this in your web.config:

<remove name="FormsAuthentication" />

I found this question looking for a very similar error, so I thought it would be good to post my solution.

Dylan
  • 1,074
  • 8
  • 8
4

Do you have something like this

<authentication mode="Forms">
 <forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>

in your web.config?

Marius B.
  • 478
  • 6
  • 18
3

For me, I needed to set the following appSetting

<add key="owin:AutomaticAppStartup" value="false"/>

to

<add key="owin:AutomaticAppStartup" value="true"/>
Warr1611
  • 435
  • 8
  • 10
2

For me, I've just deleted the cookies from Google Chrome and it worked.

bcurti
  • 75
  • 6
1

For me It has a very trivial mistake. I was authenticated yet. Owin Authentication remains the user logged in despite the browsers close. I need to express logoff with following code:

public void IdentitySignout() {
   AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie,
   DefaultAuthenticationTypes.ExternalCookie);
}
0

I had the same issue with Authorize not working. At first I thought it was the code. But everything was right - it built with no errors. I then restarted my dev machine and it started working. It worked the first time, then had the same issue with it not working. Think it must be storing the value from the first cycle and not clearing it. (only a theory)

  • 3
    This doesn't really answer the question and should probably be posted as a comment. – ZygD Jun 16 '15 at 08:39
0

I just ran into this issue today, and wanted to add my solution for anyone who might also run into this error. Nothing else worked for me. I had recently done an installer for one of the other projects in this solution, and I must have unchecked the "Build" box in Configuration Manager.

With that unchecked, it didn't re-build when I added the [Authorize] tag, even though I did make cshtml page changes that were showing up. I didn't figure it out until I put a breakpoint in my controller action and noticed that I never hit it. I even tried returning null from the controller, and the application still navigated to the new page.

So, long story short, check to make sure you are Building that project in Configuration Manager, that's what worked for me.