Azure免费网站重定向到www和找不到页面

时间:2014-09-18 01:37:04

标签: azure web

我刚刚使用Visual Studio 2013将我的MVC网站成功发布到我的免费azure网站:eyepaidstage.azurewebsites.net。

发布完成后,我的浏览器打开,找不到页面。 url eyepaidstage.azurewebsites.net已更改/重定向到www.eyepaidstage.azurewebsites.net。

我在桌面(ISP是版本)和Android移动版(ATT)上使用IE,Chrome和Firefox测试了http://eyepaidstage.azurewebsites.nethttps://eyepaidstage.azurewebsites.net

Ping和NSlookup正在妥善解决:

C:\Users\MSIH>ping eyepaidstage.azurewebsites.net

Pinging waws-prod-blu-001.cloudapp.net [168.62.48.183] with 32 bytes of data:
Request timed out.
Request timed out.

Ping statistics for 168.62.48.183:
    Packets: Sent = 2, Received = 0, Lost = 2 (100% loss),
Control-C
^C
C:\Users\MSIH>nslookup
Default Server:  Wireless_Broadband_Router.home
Address:  192.168.1.1

> eyepaidstage.azurewebsites.net
Server:  Wireless_Broadband_Router.home
Address:  192.168.1.1

Non-authoritative answer:
Name:    waws-prod-blu-001.cloudapp.net
Address:  168.62.48.183
Aliases:  eyepaidstage.azurewebsites.net
          waws-prod-blu-001.vip.azurewebsites.windows.net

>

我在Chrome中的开发者工具中发现了这一点。看起来azure IIS正在返回状态码301!

Remote Address:168.62.48.183:80
Request URL:http://eyepaidstage.azurewebsites.net/
Request Method:GET
Status Code:301 Moved Permanently (from cache)
Request Headers
Provisional headers are shown
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36
X-DevTools-Emulate-Network-Conditions-Client-Id:FC8EB51B-C0D7-4998-B2A6-4493CBE72C52
Response Headers
Content-Length:0
Date:Thu, 18 Sep 2014 00:42:54 GMT
Location:http://www.eyepaidstage.azurewebsites.net:80/
Server:Microsoft-IIS/8.0
X-Powered-By:ASP.NET

2 个答案:

答案 0 :(得分:2)

您的申请(eyepaidstage.azurewebsites.net)肯定会将301重定向返回www.eyepaidstage.azurewebsites.net。您的应用程序必须具有寻找www的逻辑。并根据需要重定向。或者,您在web.config文件中运行了一个URLRewrite,用于指定此行为。

答案 1 :(得分:0)

大多数情况下都是人为错误。我忘记了将此代码添加到global.asax.cs文件中,该文件将所有请求重定向到www。

 protected void Application_BeginRequest(object sender, EventArgs e)
        { 
            if (!Request.Url.Host.StartsWith("www") && !Request.Url.IsLoopback)
            {
                UriBuilder builder = new UriBuilder(Request.Url);
                builder.Host = "www." + Request.Url.Host;
                Response.StatusCode = 301;
                Response.AddHeader("Location", builder.ToString());
                Response.End();
            }
        }