加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 授权不在ASP.NET MVC 5中工作

发布时间:2020-12-15 08:01:01 所属栏目:百科 来源:网络整理
导读:Disclaimer: this is my first time with ASP.NET MVC 5 我不知道为什么它不起作用.我无法让我的MVC5应用程序授权用户.我在以前的版本(2,3和4)中完成了这个,但我似乎无法在OWIN中使用它. 我正在使用启用了所需功能的本地IIS: EDIT : I’m using SSL on IIS

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包添加到您的应用程序.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读