相关疑难解决方法(0)

部署在Azure Web App/Azure API上时缺少CORS标头

我创建了一个OWIN托管WebAPI 2.还有一个Web应用程序(AngularJS),它使用API​​并充当客户端.

我已经添加了必要的代码CORSStartup.cs,并主持它本地IIS比客户的不同端口上,并确认其修复Cors问题.

然后,我将这两个应用程序部署到Azure(我已将两个应用程序都放在Azure上作为Web应用程序,我也尝试将OWIN放到当前处于预览状态的Azure API中)但是 - 预检请求现在失败了(没有Access-Control-Allow-Origin出现在响应).

问:我不知道Azure的某些特定内容吗?为什么OWIN在部署时没有提供此标头,但是它正在使用localhost?我没有在应用程序的Azure刀片设置的属性窗口中看到任何约束.

笔记:

关于我正在使用的设置的一些细节:

  • 使用Owin,WebAPI2,Ninject,SignalR
  • 自定义令牌在每个后续请求的标头中发布和提供,并使用自定义过滤器进行验证.
  • 我现在正在尝试的是 *

Startup.cs的相关部分:

public void Configuration(IAppBuilder appBuilder)
{
    appBuilder.UseCors(CorsOptions.AllowAll);

    HttpConfiguration config = new HttpConfiguration();
    config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

    //bind IClientsNotifier with method returning singleton instance of hub
    var ninjectKernel = NinjectWebCommon.GetKernel();
    ninjectKernel.Bind<MySignalRHub>().ToSelf().InSingletonScope();
    ninjectKernel.Bind<QueryStringBearerAuthorizeAttribute>().ToSelf();

    GlobalHost.DependencyResolver = new NinjectSignalRDependencyResolver(ninjectKernel);
    appBuilder.Map(
        "/signalr", map =>
    {
        map.UseCors(CorsOptions.AllowAll);
        var hubConfiguration = new HubConfiguration();
        map.RunSignalR(hubConfiguration); …
Run Code Online (Sandbox Code Playgroud)

c# azure cors azure-web-sites azure-api-apps

7
推荐指数
2
解决办法
8335
查看次数

标签 统计

azure ×1

azure-api-apps ×1

azure-web-sites ×1

c# ×1

cors ×1