Jump to content

Redirect to a other url in .Net


haibec

Recommended Posts

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

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.

Hiihhihi!I don't know C# . I wan't make .htm with that function . Help me
Link to comment
Share on other sites

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...