Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4051742
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:13:57+00:00 2026-05-20T14:13:57+00:00

So in my code I want to detect if my login page is being

  • 0

So in my code I want to detect if my login page is being called http, and redirect it to https.

I know there are non code ways to skin this cat, but for frustrating technical reasosn I’m backed into doing it in code.

            if (!Request.IsSecureConnection)
            {
                string redirectUrl = Request.Url.ToString().Replace("http:", "https:");
                Response.Redirect(redirectUrl);
            }

So I drop this in my Page_Load(...), make sure my debugger uses real IIS, not VS2008s IIS, and hit debug.

Inthe debugger, waltz along, hit
Response.Redirect(“https://localhost/StudentPortal3G/AccessControl/AdLogin.aspx“),
hit f5.

Get “Internet Explorere Cannot Display the webpage, url is HTTP, not HTTPS.
Not getting an informative error… same thing happens not running in the debugger.

So what am I missing? it does not appear to be rocket science, I’ve seen similar code on lots of blogs…

What am I doing wrong? I figure it has to be a totally obvious Rookie mistake, but I’m not seeing it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T14:13:58+00:00Added an answer on May 20, 2026 at 2:13 pm

    I’d do a !Request.IsLocal as well to make sure that I’m not debugging, though if you’re using a real instance of IIS with a cert applied when debugging that shouldn’t be an issue.

    if (!Request.IsLocal && !Request.IsSecureConnection)
    {
        string redirectUrl = Request.Url.ToString().Replace("http:", "https:");
        Response.Redirect(redirectUrl, false);
        HttpContext.ApplicationInstance.CompleteRequest();
    }
    

    Note: This answer assumes an MVC context within a Controller where HttpContext is a property holding the current context. If you’re unlucky enough to still be using WebForms or are referencing the context in a degenerate way you will need to use HttpContext.Current.ApplicationInstance.CompleteRequest().

    Note: I’ve updated this to be consistent with the recommended pattern to terminate the request according to the framework documentation.

    When you use this method in a page handler to terminate a request for
    one page and start a new request for another page, set endResponse to
    false and then call the CompleteRequest method. If you specify true
    for the endResponse parameter, this method calls the End method for
    the original request, which throws a ThreadAbortException exception
    when it completes. This exception has a detrimental effect on Web
    application performance, which is why passing false for the
    endResponse parameter is recommended. For more information, see the
    End method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering how I can detect code plagiarism with Javascript. I want to
I am new to Android. I want to detect, through code, whether my android
I want code changes to take effect immediately during development. How can I detect
I want to know how can I detect if the user is already logged
I want to detect the button event in the page,I inject my script.js strong
I write two js code. I want first detect the width of the screen,
Hi I want to detect ipad orientation in php, i know i can detect
I'm writing some semi-portable code and want to be able to detect when I'm
I want to detect if a string is a valid javasript code for pass
I have the following code I want to detect the screen off of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.