this blog contains information for .net and sql stuffs. You can find various tips and tricks to overcome problem you may be facing in ...

Tuesday, August 16, 2011

Secure asp.net website URL with global.asax

Once any one has installed SSL certificate in their server, there is need to redirect old http url to https protocol. If we don’t write any custom code for redirection it will continue to browse by both of url.

There are many ways to redirection of page, we are going to take a look on global.asax file. We all are much familiar with Global.asax file in asp.net application, it handles out most of application related events.

We can use following code snippet to redirect http to https

protected void Application_BeginRequest(Object sender, EventArgs e)

{

if (HttpContext.Current.Request.IsSecureConnection.Equals(false))

{

HttpContext.Current.Response.Redirect(HttpContext.Current.Request.Url.AbsoluteUri.Replace("http://", "https://"));

}

}