目前用这样的方式,效果不对
void Application_BeginRequest(object sender, EventArgs e)
{
switch (Request.Url.Scheme)
{
case "https":
Response.AddHeader("Strict-Transport-Security", "max-age=300");
break;
case "http":
string url = Request.Path.ToLower();
if (ConfigurationManager.AppSettings["https"] == "1" && (url.Contains("/personal/") || url.Contains("/admin/")))
{
url = "https://" + Request.Url.Host + Request.Url.PathAndQuery;
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", url);
}
break;
}
}
加上Response.End()试试
不错,加了后到达预期效果
最终代码:
string url = Request.Path.ToLower();
switch (Request.Url.Scheme)
{
case "https":
if (ConfigurationManager.AppSettings["https"] == "1" && (url.Contains("/personal/") || url.Contains("/admin/")))
{
}
else
{
url = "http://" + Request.Url.Host + Request.Url.PathAndQuery;
Response.Redirect(url);
Response.End();
}
break;
case "http":
if (ConfigurationManager.AppSettings["https"] == "1" && (url.Contains("/personal/") || url.Contains("/admin/")))
{
url = "https://" + Request.Url.Host + Request.Url.PathAndQuery;
Response.Redirect(url);
Response.End();
}
break;
}
嗯.异步调用也会被转掉.你都说部分页面了.就加一个部分页面数组.检测当前url在里面的时候才跳转.
是要这样的吗?
dudu说得对。没有end。继续执行页面去了。