Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • http To https Redirection In ASP.NET

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 371
    Comment on it

    Hello Friend,

    Many times we need to implement SSL (Secure Socket Layer|) certificate on website for data security. After SSL implementation you don't want to allow page access through http://.
    If any one try to access website using http:// then he/she should be redirected in https://. So we can achieve this implementing below rule in asp.net Web.config file.

    Code:-

    1. <System.WebServer>
    2. <rewrite>
    3. <rules>
    4. <rule name="Force HTTPS" enabled="true">
    5. <match url="(.*)" ignoreCase="false" />
    6. <conditions>
    7. <add input="{HTTPS}" pattern="off" />
    8. </conditions>
    9. <action type="Redirect" url="https://{HTTP&#95;HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
    10. </rule>
    11.  
    12. </rules>
    13. </rewrite>
    14. </System.WebServer>

    We can also check visitors secure connection using Request.IsSecureConnection property. Example:-

    1. protected void Page&#95;Load(object sender, EventArgs e)
    2. {
    3. if (!Request.IsSecureConnection) // check is secure connection used or not
    4. {
    5. Response.Redirect(Request.Url.AbsoluteUri.Replace("http://", "https://"));
    6. // redirect visitor to http to https
    7. }
    8. }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: