Avatar of roddev
roddev asked on

asp.net c# have a page use https

in page_load I'm trying:



            //this is the current url

            System.Uri currentUrl = System.Web.HttpContext.Current.Request.Url;

            //don't redirect if this is localhost

            if (!currentUrl.IsLoopback)
            {

                if (!currentUrl.Scheme.Equals(Uri.UriSchemeHttps, StringComparison.CurrentCultureIgnoreCase))
                {

                    //build the secure uri

                    System.UriBuilder secureUrlBuilder = new UriBuilder(currentUrl);

                    secureUrlBuilder.Scheme = Uri.UriSchemeHttps;

                    //use the default port.

                    secureUrlBuilder.Port = -1;

                    //redirect and end the response.

                    System.Web.HttpContext.Current.Response.Redirect(secureUrlBuilder.Uri.ToString());

                }

            }  


but get an error :/


i.e. my payment screens need to use https
i.e. my profile screens need to use https

I thought this would work but it fails :/
ASP.NET

Avatar of undefined
Last Comment
roddev

8/22/2022 - Mon
ASKER
roddev

it does replace http with https
Miguel Oz

Please check that your site has SSL (HTTPS) enabled.
E.g. If you use your HTTPS URL in the browser does it work OK? (The wb page does not show error above)
Also you need to check if you have proxy or firewall restrictions.
ASKER CERTIFIED SOLUTION
Gary

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
roddev

the sad thing is the control panel has the ssl certificates installed.  however it apparently does NOT setup IIS even though it says its got https configured.  I'll install the certificates on IIS itself and not let the control panel know about it (just like I had to run everything in the application pool for .net 4.0)
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER
roddev

not really