https and http issues ...

an ssl certifiacte was installed and I would like to add a fucntionalit which will detect whether or not person is coming from HTTP or HTTPS and if a person is accessing a login URL by typing in HTTP it should redirect him to HTTPS version. Please take a look at the below code. It seems that this code executes all the time and it doesn't get to other parts of the code. I added Response.Write at the bottom for testing purposes and I never get to that line, code redirects to https and a loging functionality is ignored.

                        if (Page.Request.Url.Scheme.ToLower() != "https")
                              Response.Redirect("https://" + Page.Request.Url.AbsoluteUri.Substring(Page.Request.Url.AbsoluteUri.IndexOf(Page.Request.Url.Host)));

//login functionality starts here
Response.Write("Login Functionality");
Who is Participating?
think you should remove if(Page.IsPostBack)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.