asp.net 我在后台做了一个驱除 www 的方法
void Application_BeginRequest(object sender, EventArgs e)
{
string FromHomeURL = "http://www.adidas.stooges.com.my";
string ToHomeURL = "http://adidas.stooges.com.my";
string a = HttpContext.Current.Request.Url.ToString().ToLower();
if (HttpContext.Current.Request.Url.ToString().ToLower().Contains(FromHomeURL))
{
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location",
Request.Url.ToString().ToLower().Replace(FromHomeURL, ToHomeURL));
}
}
这样导致了我的 ajax 请求失败了 !
我实在 http://adidas.stooges.com.my GET request from http://www.adidas.stooges.com.my/ajax.ashx
在 ashx 我给了 Response.AddHeader("Access-Control-Allow-Origin", "*"); 可是还是报错
我对原理还是不怎么了解。高手指点一下吧... 如果我把Application_BeginRequest事件移除,访问就正常了
Ajax
ASP.NET
------解决方案--------------------
http://adidas.stooges.com.my
http://www.adidas.stooges.com.my/ajax.ashx
你这2个就不同源,IE下open发送请求的时候直接报错了
firefox等w3c浏览器没有检查Access-Control-Allow-Origin这个响应头,应该会报错,你可以试试返回access这个头
ajax.ashx 不需要返回了,因为转向后已经同源
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");/////////
HttpContext.Current.Response.AddHeader("Location",