我們有一個簡單的要求使用https對於asp.net 4.0 web應用程序中的某些特定頁面。爲了檢查我們的實現,我們爲IIS 7部署了一個簡單的asp.net 4.0應用程序。該應用程序已被編碼,以基於web.config標誌通過https將default.aspx頁面重定向到securepage.aspx。HTTP到HTTPS重定向在asp.net不工作
protected void Page_Load(object sender, EventArgs e)
{
Uri requestUri = Page.Request.Url;
UriBuilder builder = new UriBuilder("https", requestUri.Host, requestUri.Port, "SecurePage.aspx");
string secureUrl = builder.Uri.ToString();
if (bool.Parse(ConfigurationManager.AppSettings["UseSecure"]))
{
Response.Redirect(secureUrl, true);
}
else
{
Response.Write(secureUrl);
}
}
但是經過我們對部署IIS 7這個程序並加載Default.aspx頁面,顯示「Internet Explorer無法顯示該網頁」。但是如果我們關閉配置標誌,它會正確顯示頁面。該應用程序在端口82上具有http綁定,在端口444上具有https。
任何人都可以指出我們要出錯的地方。
兩個答案的女巫是一個工作,一個用'http'或一個用'https'?或兩者 ?因爲答案有這麼小的不同。 – Aristos
兩者都會根據需要工作。主要觀點是關於https端口與http請求端口相同 – koder