Authorization does not work in ASP.NET MVC 5

Disclaimer: This is my first time with ASP.NET MVC 5

I have no idea why this is not working. I cannot force my MVC5 application to allow users. I did this in previous versions (2, 3, and 4), but I can't get it to work in OWIN.

I am using local IIS with features enabled:

IIS Features

EDIT :

I use SSL for IIS and RequireHttps in C #

This is the code:

protected void Application_Start() { GlobalFilters.Filters.Add(new AuthorizeAttribute()); } 

Startup.Auth.cs

 app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/admin/account/login") }); app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); app.UseGoogleAuthentication(); 

Despite the fact that I use Global Authorize, I tried to "get" him to see if this problem was:

 public class HomeController : Controller { [Authorize] public ActionResult Index() { return View(); } } 

No luck ... I'm not sure if this was necessary with OWIN, but I even tried to enable forms authorization:

 <authentication mode="Forms" /> 

EDIT [2]

Ok, I figured out the problem ... IIS! Finally! Now, does anyone know how to fix this? Do I need anything special to run OWIN IIS? Now I can work, but soon I will have to deploy the application and probably encounter the same problem on the server ...

I had read:

How do you log in / authenticate a user with the RTM bits of Asp.Net MVC5 using AspNet.Identity?

Authorize attribute does not work MVC 5

Any ideas?

+7
c # authorization asp.net-mvc-5 owin
source share
2 answers

Since your application works with IIS, try adding the Microsoft.Owin.Host.SystemWeb nuget package to your application.

+2
source share

Try this article, it was useful for me to configure OWIN . I’m not sure if you used claims, because you didn’t indicate in your question what is important for creating an authentication ticket for authentication

Also, since you are using SSL, pay attention to the CookieSecure property if it still does not work CookieSecureOption

 app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/admin/account/login") CookieSecure = CookieSecureOption.Never }); 

I hope this helps

+2
source share

All Articles