首页 > 解决方案 > 在发布版本中的 .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 }
            );
        }

标签: c#oauth-2.0c#-3.0c#-2.0.net-framework-version

解决方案


推荐阅读