Disclaimer: this is my first time with ASP.NET MVC 5
我不知道为什么它不起作用.我无法让我的MVC5应用程序授权用户.我在以前的版本(2,3和4)中完成了这个,但我似乎无法在OWIN中使用它.
我正在使用启用了所需功能的本地IIS:
EDIT:
I’m using SSL on IIS and RequireHttps at C#
这是代码:
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();
即使我正在使用全局授权,我试图“强制”它,看看这是不是问题:
public class HomeController : Controller { [Authorize] public ActionResult Index() { return View(); } }
没运气…
我不确定OWIN是否有必要,但我甚至尝试过启用表单身份验证:
<authentication mode="Forms" />
EDIT [2]
Well,I found out the problem… IIS! Finally! Now,would
anyone know how to fix that? Do I need anything special to run OWIN on
IIS? I can work now,but soon I’ll have to deploy the app and will
probably run into the same problem in the server…
我已经读过这些了:
How do you login/authenticate a user with Asp.Net MVC5 RTM bits using AspNet.Identity?
Authorize attribute not working MVC 5
有任何想法吗?
解决方法
由于您的应用程序使用IIS运行,请尝试将
Microsoft.Owin.Host.SystemWeb
nuget包添加到您的应用程序.