haibec Posted September 29, 2006 Share Posted September 29, 2006 Hi Guys!my Webser installed HTTPS. I want when user access my Web. (Exemple :http://myweb) the system auto redirect to https://myweb. My web code by ASPX. Please help me Link to comment Share on other sites More sharing options...
aspnetguy Posted September 29, 2006 Share Posted September 29, 2006 use the following function as the first to get executed on each page private void ensureHttps(){ string url = Request.ServerVariables["REMOTE_ADDR"].ToString(); string protocol = url.Substring(0,5); if(String.Compare("https",protocol) != 0) { url = url.Split(':')[1].Replace("//",String.Empty); Response.Redirect("https://" + url); }} I have not had time to check this so there may be some small logic errors but ti demonstrates the basic idea. Link to comment Share on other sites More sharing options...
haibec Posted September 30, 2006 Author Share Posted September 30, 2006 use the following function as the first to get executed on each pageprivate void ensureHttps(){ string url = Request.ServerVariables["REMOTE_ADDR"].ToString(); string protocol = url.Substring(0,5); if(String.Compare("https",protocol) != 0) { url = url.Split(':')[1].Replace("//",String.Empty); Response.Redirect("https://" + url); }} I have not had time to check this so there may be some small logic errors but ti demonstrates the basic idea. Hiihhihi!I don't know C# . I wan't make .htm with that function . Help me Link to comment Share on other sites More sharing options...
aspnetguy Posted September 30, 2006 Share Posted September 30, 2006 you can't you would have to make it a .aspx page like this. <%@ Page Language="C#" %><script runat="server">private void Page_Load(object sender, EventArgs e){ ensureHttps();}private void ensureHttps(){ string url = Request.ServerVariables["REMOTE_ADDR"].ToString(); string protocol = url.Substring(0,5); if(String.Compare("https",protocol) != 0) { url = url.Split(':')[1].Replace("//",String.Empty); Response.Redirect("https://" + url); }}</script><html><head> <title></title></head><body></body></html> If you insist it must be done with a .htm page you will have to use JavaScript, but that is unreliable since users can turn it off. If you still want it I can write you a javascript to do this. Would you like me to? Link to comment Share on other sites More sharing options...
haibec Posted September 30, 2006 Author Share Posted September 30, 2006 you can't you would have to make it a .aspx page like this.<%@ Page Language="C#" %><script runat="server">private void Page_Load(object sender, EventArgs e){ ensureHttps();}private void ensureHttps(){ string url = Request.ServerVariables["REMOTE_ADDR"].ToString(); string protocol = url.Substring(0,5); if(String.Compare("https",protocol) != 0) { url = url.Split(':')[1].Replace("//",String.Empty); Response.Redirect("https://" + url); }}</script><html><head> <title></title></head><body></body></html> If you insist it must be done with a .htm page you will have to use JavaScript, but that is unreliable since users can turn it off. If you still want it I can write you a javascript to do this. Would you like me to? If you help me . I'm very thank to you!you can't you would have to make it a .aspx page like this.<%@ Page Language="C#" %><script runat="server">private void Page_Load(object sender, EventArgs e){ ensureHttps();}private void ensureHttps(){ string url = Request.ServerVariables["REMOTE_ADDR"].ToString(); string protocol = url.Substring(0,5); if(String.Compare("https",protocol) != 0) { url = url.Split(':')[1].Replace("//",String.Empty); Response.Redirect("https://" + url); }}</script><html><head> <title></title></head><body></body></html> If you insist it must be done with a .htm page you will have to use JavaScript, but that is unreliable since users can turn it off. If you still want it I can write you a javascript to do this. Would you like me to? I run it and have error:Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.Source Error: Line 13: if(String.Compare("https",protocol) != 0)Line 14: {Line 15: url = url.Split(':')[1].Replace("//",String.Empty);Line 16: Response.Redirect("https://" + url);Line 17: } help me! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now