2010-05-24 64 views
1

如何在使用c#编译为dll的类文件中的application_beginrequest事件中将http重定向到同一个域到https。如何重定向到同一个域从http到https

我不能重定向到同一台服务器......任何建议...

+0

为什么不这样做在IIS设置? (对于iIS 7/7.5,这将在'web.config'中。) – Richard 2010-05-24 13:49:51

+0

@Richard Ardman的答案可以在web.config中完成吗?如何? – 2010-09-29 11:50:15

+0

@Lieven:是的,请在UI中查看它,看看它对web.config文件所做的更改(如果在全局级别完成,它将位于全局web.config当然)。 – Richard 2010-09-29 12:00:04

回答

0
if (Request.Url.ToString.ToLower.StartsWith("http://")) { 
    Response.Redirect(Request.Url.ToString.Replace("http://", "https://")); 
} 
1
//Check if page is running under https. If not redirect to secure page... 
if ((!HttpContext.Current.Request.IsSecureConnection)) 
{ 
    HttpContext.Current.Response.Redirect("https://" + Context.Request.Url.Host + Context.Request.Url.PathAndQuery); 
} 
+0

这可以在web.config中完成吗? – 2010-09-29 11:49:56