c# - 在发布版本中的 .net 框架中出现 cors 错误
问题描述
在调试模式下一切正常,但在发布模式下我面临 cors 错误
我现在使用 oauth 进行身份验证,我允许所有来源,但是当我尝试获取令牌时,我收到了 cors 错误
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Configure the application for OAuth based flow
PublicClientId = "self";
并且也在 webapiconfig 中提供
public static void Register(HttpConfiguration config)
{
config.EnableCors(new EnableCorsAttribute("*","*","*"));
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
UnityConfig.RegisterComponents();
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
解决方案
推荐阅读
- mysql - 如何在 MYSQL 中将 MM/YY 转换为 YYYY-MM-DD
- r - 不同列中值比例的条形图
- c++ - 关闭 linux systemd 时向我的应用程序发送多个 sigterm 信号
- c# - 将 XML 文档中的值读入 Int Array c#
- php - 以混合方式分布顺序数组项
- azure - Qna 制造商返回具有高置信度分数的答案,例如不在 KB 中的“abcd”,对于这些值,azure search 也返回 null
- powerpoint - PowerPoint中的可重用/动态/实例/符号对象(hack)?
- laravel - 实时获取 Pusher 连接状态
- rust - `T + T`没有实现
- alexa - 如何在 Alexa Amazon 中拆分长演讲