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
Avatar of roddev
roddev

ASKER

User generated image
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

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
Avatar of Gary
Gary
Flag of Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of roddev
roddev

ASKER

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)
Avatar of roddev
roddev

ASKER

not really
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo