troubleshooting Question

asp.net c# have a page use https

Avatar of roddev
roddev asked on
ASP.NET
5 Comments1 Solution313 ViewsLast Modified:
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 :/
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros