Billa
Billa

Reputation: 5266

Url rewriting with https

I have the below urls

http://www.mywebsite.com/home

https://www.mywebsite.com/secure/reports/

When user enters the above url we load

http://www.mywebsite.com/home.aspx

https://www.mywebsite.com/secure/reports.aspx

The problem is, if the user enter like https://www.mywebsite.com/home, need to redirect to http://www.mywebsite.com/home. Just remove change https to http, since it is not secured

Similarly, If user enters http://www.mywebsite.com/secure/reports, we need to redurect to secure https://www.mywebsite.com/secure/reports

Upvotes: 1

Views: 71

Answers (2)

dipz
dipz

Reputation: 11

Make changes to your Web.Config

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

More references: Check- http://www.jppinto.com/2010/03/automatically-redirect-http-requests-to-https-on-iis7-using-url-rewrite-2-0/

Upvotes: 0

user1968030
user1968030

Reputation:

see this:

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

Upvotes: 1

Related Questions