http to https redirect not working

I would like to redirect my page from http to https protocol but am having difficulties. Here is what I've tried so far:

Adding the following to global.asax

protected void Application_BeginRequest(Object sender, EventArgs e)
    if (!Request.IsLocal && !Request.IsSecureConnection)
        if (HttpContext.Current.Request.IsSecureConnection || HttpContext.Current.Request.IsLocal)
            Response.Redirect("https://" + Request.ServerVariables["HTTP_HOST"] + HttpContext.Current.Request.RawUrl);

Adding the following to every page

protected override void OnPreInit(EventArgs e)
    if (!IsPostBack)

private void RedirectAccordingToRequiresSSL()
    if (!Request.IsLocal && !Request.IsSecureConnection)
        if (!Request.IsSecureConnection) // Need to redirect to https

private void RedirectAccordingToRequiresSSL(string scheme)
    var url = scheme + Uri.SchemeDelimiter + Request.Url.Authority + Request.Url.PathAndQuery;
    Response.Redirect(url, false);

Adding a rewrite to web.config, but I think rewrite element itself is not working properly

        <rule name="Redirect HTTP to HTTPS" stopProcessing="true">
          <match url="(.*)"/>
            <add input="{HTTPS}" pattern="^OFF$"/>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther"/>

No matter what I try, entering in will never redirect to Error I keep getting is 403 (forbidden). Typing the URL in directly with https however works great. Any help would be greatly appreciated.


I just tried locally and I can get a redirect from http to https with the following rule.

enter code here
<rule name="TO SSL" patternSyntax="Wildcard" stopProcessing="true">
    <match url="*" />
    <conditions logicalGrouping="MatchAny">
        <add input="{HTTPS}" pattern="Off" />
    <action type="Redirect" url="https://{HTTP_HOST}{URL}" />

Example Fiddler Trace

Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36

HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=UTF-8
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Wed, 12 Feb 2014 01:14:49 GMT
Content-Length: 154

Need Your Help

AngularJS: Why not write logic in controller?

angularjs angularjs-directive standards angularjs-controller

Pardon me if this sounds stupid but I have been using AngularJS for a while now and everywhere I have seen people telling me to wrap my logic in a directive(or service ?) instead of my controller and

Apache Mod_Rewrite Multiple Levels

php apache .htaccess mod-rewrite

My goal is to make some friendly URL's using .htaccess. I need a mod_rewrite (for .htaccess) solution that allows me to have URLs like: