我一直在尋找關於這個問題幾天,並做了大量的研究,但我無法弄清楚這一點。HTTP到HTTPS瀏覽器問題
我想控制我的網頁重定向到http或https,無論我需要或不。
我創建了一個attrubte把每一頁,我需要在HTTPS
[AttributeUsage(AttributeTargets.Class)]
public sealed class RequireSSL : Attribute { }
運行上方。然後我有一個HTTP模塊運行檢查要求每一頁。
public class DartsGhentPipeline : IHttpModule
{
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += Context_PreRequestHandlerExecute;
}
private void Context_PreRequestHandlerExecute(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpRequest request = application.Request;
HttpResponse response = application.Response;
Page page = application.Context.CurrentHandler as Page;
if (page == null)
return;
bool requireSSL = page.GetType().GetCustomAttributes(typeof(RequireSSL), true).Length > 0;
bool isSecureConnection = request.IsSecureConnection;
string url = string.Format("{0}://www.dartsghent.be{1}", requireSSL ? Uri.UriSchemeHttps : Uri.UriSchemeHttp, HttpContext.Current.Request.RawUrl);
if (requireSSL != isSecureConnection)
response.RedirectPermanent(url);
}
public void Dispose() { }
}
這裏的問題是,當我重定向到相同的網址或任何其他。瀏覽器拒絕從http切換到https或其他方式導致重定向循環,瀏覽器將阻止這種情況發生。
我發現我的網站運行完美時,我用www替換我的網址。或沒有www。但我不能使用此subwebsite我有test.dartsghent.be
任何人都可以告訴我如何解決這個問題,請沒有urlrewriter模塊pls。
任何幫助表示讚賞
注:我沒有使用MVC
正如你所看到的頁面不斷重定向本身。我使用RedirectPermanent(url)來https,但即使重定向被觸發,它也不會移動到https,因此它一直在嘗試。
你是什麼意思「瀏覽器拒絕切換」?你看到在響應中設置了正確的重定向頭(使用瀏覽器開發工具)嗎?究竟是什麼意外的瀏覽器行爲? –
在Chrome中,我得到以下行爲 http:// dartsghent。be - > https://wwww.dartsghent.be =成功 http://dartsghent.be - > https://dartsghent.be =頁面將保留在http協議 –
我測試的越多,越多認爲問題在重定向。即使我明確告訴我的重定向到https鏈接。它看起來像重定向正在移動我自己重定向到相同的協議,因爲它現在在只要域是相同的。任何解決方案? –