Skip to main content

Posts

Showing posts with the label redirect http to https asp net mvc

Redirect http to https ASP.Net MVC

Hello everyone, I am going to share the code sample for redirect http to https ASP.Net MVC projects using the different types of techniques. The techniques types as given belows. Types 1: You can add the below code in Global.asax.cs for redirect http to https. protected void Application_BeginRequest( Object sender, EventArgs e) {     var httpRequest = HttpContext .Current.Request;     if (httpRequest.IsSecureConnection.Equals( false ) && httpRequest.IsLocal.Equals( false ))     {         Response.Redirect( " https ://" + Request.ServerVariables[ "HTTP_HOST" ] + httpRequest.RawUrl);     } } OR Types 2: You can add the below code in Global.asax.cs for redirect http to https. protected void Application_BeginRequest( Object sender, EventArgs e) {     switch (Request.Url.Scheme)     {    ...