单页的HTTPS(使用Global.asax Application_BeginRequest方法) [英] HTTPS for single page (using Global.asax Application_BeginRequest method)
问题描述
我只想要HTTPS只用于login.aspx,而其他所有页面都是普通的http。
Hi,
I want HTTPS for only login.aspx , and for all other pages normal http.
void Application_BeginRequest(object sender, EventArgs e)
{
var absolutepath = Request.Url.AbsolutePath;
var ext = System.IO.Path.GetExtension(Request.Url.AbsolutePath);
if (absolutepath.Contains("login.aspx") || absolutepath.ToLower().Contains("webresource.axd") || ext.ToLower() == ".png" || ext.ToLower() == ".css" || ext.ToLower() == ".js" || ext.ToLower() == ".jpg" || ext.ToLower() == ".gif")
{
if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("http:"))
{
Response.Redirect(HttpContext.Current.Request.Url.ToString().ToLower().Replace("http:", "https:"));
}
}
else
{
if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("https:"))
{
Response.Redirect(HttpContext.Current.Request.Url.ToString().ToLower().Replace("https:", "http:"));
}
}
}
这是我的方法。
这个问题是,当login.aspx在后台加载jpg,png,css时,这是
js,axd文件正在加载。它们都没有转换为HTTPS证书,而且收到错误。所以我把它们包含在if条件和login.aspx
但是当我想将https转换为http时,它只转换为https而不是http。因为我把条件置于第一IF状态。
我在这里需要的帮助是。我想将所有背景文件转换为https,如果页面是login.aspx,否则为http。
谢谢。
This is my method.
The problem in this is ,
when login.aspx is loading in background all jpg,png,css,js,axd files are loading. None of them converted into HTTPS certificate and it is getting error. So i included them in if condition along with login.aspx
But When i want to convert https to http, it converts into https only instead of http. Because i put the condition in first IF condition.
The help i required here is. I want to convert all the background files to https, if the page is login.aspx , otherwise http.
Thank you.
推荐答案
参考这篇文章自动在HTTP和HTTPS之间切换:版本2 [ ^ ]
这篇关于单页的HTTPS(使用Global.asax Application_BeginRequest方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!