Monday, August 29, 2011

ASP.NET: Automatically convert http urls into https url

Sometimes we need to navigate securely within the website because of some confidential information. The user might use just http but we need to change it into https. So the approach I like best is to do it in masterpage level. We can write a small code snippet in the page load section of the masterpage which checks if the page is http or not. If it is http then changes it to https. Following are the line of codes that we need to put in the master page's page load function. I did not come up with these code, I collected it from the internet. So I am not taking any credit for the code ;)

//Redirect to https if typed http.

string redirectUrl = null;
HttpContext context = HttpContext.Current;

// if we want HTTPS and it is currently HTTP
if (!context.Request.IsSecureConnection)
{
redirectUrl = context.Request.Url.ToString().Replace("http:", "https:");
}

// check if we need to redirect, and if so use redirectUrl to do the job
if (redirectUrl != null)
context.Response.Redirect(redirectUrl);

Hope it helps. :)

Thursday, August 25, 2011

ASP.NET: How to create a custom error page.

ASP.NET has this useful feature that you can set a custom error page. Whenever an error occurs in the system, you are automatically redirected to the custom error page. By using this feature you can avoid showing the ugly yellow page and the error details to the user. How to implement this? Well the following link has described it all in details. :)
http://www.asp.net/hosting/tutorials/displaying-a-custom-error-page-cs

** I believe when there are so many quality tutorials over the web, I do not really need to write one of my own unless the topic is something unique**

Wednesday, August 10, 2011

ASP.NET: How to save the result found from database query in an excel file and let the user download that file

I was exactly looking for this solution and found that msdn already has what I needed (as usual). Here is the link:

http://support.microsoft.com/default.aspx?scid=kb;en-us;311194

** I believe when there are so many quality tutorials over the web, I do not really need to write one of my own unless the topic is something unique**

Wednesday, August 3, 2011

ASP.NET: Adding check/uncheck all button with a gridview.

It is a common question for many developers that
1) How to add a checkbox that appears with each row of a gridview.
2) How to implement check/uncheck all functionality.

I found a useful tutorial on the internet which pretty much covers both of the above questions.
Take a look at this here:

http://wiki.asp.net/page.aspx/281/check-uncheck-checkboxes-in-gridview-using-javascript/

** I believe when there are so many quality tutorials over the web, I do not really need to write one of my own unless the topic is something unique**