How to Auto Redirect from HTTP To HTTPS IN Asp.Net using Web Config
Auto Redirect from HTTP to HTTPS
So, for adding auto redirect in your Asp.net Web application we can use web config file. As changing in web config file is easier and effective.
So, for forcing auto redirect from http to https we have to add rewrite rules in our web config file.
These rules must be added in <System.WebServer> node , as showed below.
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <remove name="Http to Https" /> <clear /> <rule name="Redirect all requests to https" stopProcessing="true"> <match url="(.*)" /> <conditions logicalGrouping="MatchAll"> <add input="{HTTPS}" pattern="off" ignoreCase="true" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="true" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
After, adding this now save your web config and run the project. You will see your site is automatically redirected from http to https.
So this is how we can achieve auto redirect from http to https in Asp.Net Web Application.