当前位置: 代码迷 >> Ajax >> 301 moved permanently ajax 的有关问题
  详细解决方案

301 moved permanently ajax 的有关问题

热度:637   发布时间:2013-09-05 16:02:07.0
301 moved permanently ajax 的问题
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",
  相关解决方案