<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script>
$.get("http://example.com/", function(data) {
alert(data);
});
</script>
Run Code Online (Sandbox Code Playgroud)
它对该URL执行OPTIONS请求,然后从不使用任何内容调用回调.
当它不是跨域时,它工作正常.
不应该只是jQuery与一个<script>节点进行调用,然后在加载时进行回调吗?我明白我无法得到结果(因为它是跨域的),但那没关系; 我只是希望电话通过.这是一个错误,还是我做错了什么?
我试图以这种方式在.NET Core中启用CORS:
public IConfigurationRoot Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options => options.AddPolicy("AllowAll", p => p.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()));
services.AddMvc();
}
public void Configure(IApplicationBuilder app)
{
app.UseCors("AllowAll");
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我向Angular 2发送请求到我的应用程序时,我得到了名人
"请求的资源上没有'Access-Control-Allow-Origin'标头."
错误信息.
我也使用Windows身份验证+ WebListener.如果我与邮递员核对,唯一的响应标题是:
Content-Length→3533 Content-Type→application/json; charset = utf-8日期→星期五,2016年10月14日12:17:57 GMT服务器→Microsoft-HTTPAPI/2.0
所以必须仍然配置错误.有什么建议?
如果我删除了outcommented行它,但我需要Windows身份验证:-(
var host = new WebHostBuilder()
.UseWebListener()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
//.UseWebListener(options => options.Listener.AuthenticationManager.AuthenticationSchemes = AuthenticationSchemes.NTLM)
.Build();
Run Code Online (Sandbox Code Playgroud)