Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Connie DeCinko 931 posts 1160 karma points
    Apr 06, 2011 @ 17:51
    Connie DeCinko
    0

    Force https requests to http?

    This isn't so much an Umbraco question, but I thought I would throw it out there in case anyone has an idea.

    With IIS 7, if a user tries to load my site via https and I don't have an SSL cert (don't need one yet), they get an ugly browser error.  How can I either redirect them to the http version of the page or present a custom (looks like my site) error message?

    It does not appear that an actual http response code is being sent and since no page is loaded, any code in my Page_Load event is ignored.

     

  • Pasang Tamang 258 posts 458 karma points
    Apr 06, 2011 @ 18:04
    Pasang Tamang
    0

    Hi Connie,

    Faced same problem before. I did solved it by assigning domain name begining with both https and http and placed below code in template's head section

    <script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
    if(Request.ServerVariables["https"] == "on")
    {
    Response.Redirect(Request.Url.ToString().Replace("https:", "http:"));
    }
    }
    </script>

    Thanks

    Pnima

  • Connie DeCinko 931 posts 1160 karma points
    Apr 06, 2011 @ 18:09
    Connie DeCinko
    0

    Hi Pasang,

    How were you able to assign the https domain?  If I try and add an https binding in IIS, it won't let me do anything if I don't add a cert.

     

  • Pasang Tamang 258 posts 458 karma points
    Apr 06, 2011 @ 18:13
    Pasang Tamang
    0

    For my website I just right click to get edit binding and from there I added domain with type https.

    Pnima

  • Connie DeCinko 931 posts 1160 karma points
    Apr 06, 2011 @ 19:47
    Connie DeCinko
    0

    Not to be a pain, but this is what I see...  the OK is greyed out and I cannot add the binding.

     

  • Pasang Tamang 258 posts 458 karma points
    Apr 06, 2011 @ 20:07
    Pasang Tamang
    0

    Oh, this is the case? You haven't create certificate in your iis. You can create certificate by choosing top root of your iis(possibility your computer name) and then you will find Server Certificates in right pane. From there you can create certificate and while binding with https type you just choose frienldy name of your certificate in ssl certificate

    Thanks

    Pnima

  • Pasang Tamang 258 posts 458 karma points
    Apr 06, 2011 @ 20:14
    Pasang Tamang
    0

    Hi

    Here I found one good article about creating server certificates http://www.sslshopper.com/article-installing-an-ssl-certificate-in-windows-server-2008-iis-7.0.html

    Thanks

    Pnima

  • Connie DeCinko 931 posts 1160 karma points
    Apr 06, 2011 @ 20:46
    Connie DeCinko
    0

    Ah, see that's where we have the confusion.  On this server/site we don't have an SSL cert and don't need one until perhaps next year.  No one can view the site via https, but when they try they get denied with an ugly browser error.  I was hoping to change that, in case there happen to be links or bookmarks out there to https pages or similar.

     

  • Connie DeCinko 931 posts 1160 karma points
    Apr 13, 2011 @ 18:10
    Connie DeCinko
    0

    Anyone?

  • Rich Green 2246 posts 4008 karma points
    Apr 13, 2011 @ 18:20
    Rich Green
    0

    You can try adding this to your urlrewriting.config file

    <add name="KickToHttps" virtualUrl="^http\://www.yourdomain.com/" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="https://www.yourdomain.com/" redirect="Domain" redirectMode="Permanent" ignoreCase="true" />

    <add name="KickToHttps" virtualUrl="^http\://www.yourdomain.com/(.*)" destinationUrl=https://www.yourdomain.com/$1 redirect="Domain" redirectMode="Permanent" ignoreCase="true" />

  • Rich Green 2246 posts 4008 karma points
    Apr 13, 2011 @ 18:25
    Rich Green
    0

    Sorry wrong way around (post editing does not seem to be working)

    <add name="KickToHttp" virtualUrl="^https\://www.yourdomain.com/"
    rewriteUrlParameter="ExcludeFromClientQueryString"
    destinationUrl="http://www.yourdomain.com/"
    redirect="Domain"
    redirectMode="Permanent"
    ignoreCase="true" />
    
    <add name="KickToHttp" virtualUrl="^https\://www.yourdomain.com/(.*)"
    destinationUrl=http://www.yourdomain.com/$1
    redirect="Domain"
    redirectMode="Permanent"
    ignoreCase="true" />
  • Jonathan Lathigee 56 posts 99 karma points
    Apr 15, 2011 @ 17:34
    Jonathan Lathigee
    0

    You can also add an "unverified" cert to your IIS -- ie a cert that is self-generated and isn't actually backed up by a signing authority (like geotrust, etc), and then swap it out when you get your "real" cert

  • Connie DeCinko 931 posts 1160 karma points
    Apr 18, 2011 @ 18:10
    Connie DeCinko
    0

    We have no plans to add a cert to this server for several months.

    I don't think the URL rewrite will work if the request never makes it to the site in order to be processed.

     

  • Matthew Hurst 1 post 21 karma points
    May 03, 2011 @ 17:05
    Matthew Hurst
    0

    I've done something similar to this with a custom HttpModule, but the other way around (forcing https).  In the HttpModule, bind a new EventHandler on context.PreRequestHandlerExecute.  For your purposes, I think that function would look something like:

            void OnPreRequestHandlerExecute(object sender, EventArgs e)
            {
                if (application.Request.Url.Scheme == "https")
                { // Rebuild the requested Uri with "http" as the scheme var uriBuilder = new UriBuilder(new Uri(application.Request.Url,application.Request.RawUrl)); uriBuilder.Scheme = "http"; uriBuilder.Host = requestHost;
                    // You might have to use uriBuilder.Uri.GetComponents() to build this redirect in the right way application.Response.Redirect(uriBuilder.ToString());
                }
            }

     

    Anyway you do it, you will need to create a certificate under IIS.  You can do a self-signed one just to set up the binding, and the above code should prevent IIS from ever trying to serve that certificate.  At least, I'm pretty sure that's how it will work...  

    Scott Gu on Enabling Self-Signed Certs
    http://weblogs.asp.net/scottgu/archive/2007/04/06/tip-trick-enabling-ssl-on-iis7-using-self-signed-certificates.aspx

Please Sign in or register to post replies

Write your reply to:

Draft