无法从不同项目中的站点授权WEB API请求

 噬天1986 发布于 2023-01-07 10:28

我认为,在Visual Studio中我认为是一种非常常见的解决方案模式:

    ASP.NET MVC项目,具有多个角度支持的ASP.NET视图

    将API数据提供给angularjs的WEB API v2项目

我正在使用OWIN与auth存储在应用程序cookie方法MVC和WEB API项目有这个配置:

    app.UseCookieAuthentication(new CookieAuthenticationOptions             {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        LoginPath = new PathString("/Account/Login"),
        LogoutPath = new PathString("/Account/Logout"),
        CookieDomain = CloudConfigurationManager.GetSetting("AuthCookieDomain"),
        CookieSecure = CookieSecureOption.Always,
        CookiePath = "/",
        CookieHttpOnly = false,
        ExpireTimeSpan = TimeSpan.FromDays(365),
        SlidingExpiration = true,           });

    // Use a cookie to temporarily store information about a user logging in with a third party login provider          app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

Web API要求对每个调用进行身份验证:

    config.Filters.Add(new AuthorizeAttribute());

Cors已启用,OWIN的Cors安装在Web API项目中.这两个项目都在https:// localhost下运行,但目前使用不同的端口如果我通过浏览器登录MVC站点并在web api方法上进行GET,一切都很好.但是,如果网站提出请求,则会获得联合国授权.

有什么建议?

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有