我创建了一个OWIN托管WebAPI 2.还有一个Web应用程序(AngularJS),它使用API并充当客户端.
我已经添加了必要的代码CORS到Startup.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)