Friday, June 1, 2012

Expiring a page on clicking browser back button in Asp.net?

It is most common in some scenarios for us to expire a page as soon as the user clicks the back button in the web browser. This will be needed in scenarios like, when registering a new user or company in our web application.


For all who need this, I thought of sharing the code which will accomplish the same.


Response.Expires = -1;
Response.Cache.SetNoServerCaching();
Response.Cache.SetAllowResponseInBrowserHistory(false);
Response.CacheControl ="no-cache";
Response.Cache.SetNoStore();


Just paste the above code in the Page_Load event of your asp.net web page for which you want to expire when user clicks browser back button.


Wednesday, May 2, 2012

How to find the port no of SQL server instance?

The default port of SQL server instance will be normally 1433, for more information please refer the below link


http://support.microsoft.com/kb/287932

But It is not necessary that the SQL server instance will operate in the default port in all client places .You can find the port of SQL server 2008 instance by going to .Start->programs->Microsoft SQL Server 2008 R2->Configuration Tools->SQL Server Configuration Manager.

In SQL Server Configuration Manager go to, SQL Server Network Configuration->protocols for MSQLSERVER->double click TC/IP.

Please refer the below link for more options
http://decipherinfosys.wordpress.com/2008/01/02/finding-the-port-number-for-a-particular-sql-server-instance/
Please see the screen shot below for more details

Sunday, January 8, 2012

What will happened if continue statement is placed in a for Loop?

What will happened if continue statement is placed in a for Loop?


Continue statement is used in c# to set control to the beginning of the loop.

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
for (int i = 0; i <= 10; i++)
{
Console.WriteLine (i.ToString());
continue;
Console.WriteLine("Iam never printed");
}
}
}
}

For example in the below code the line Console.WriteLine("Iam never printed"); is never executed because the control is set back to the beginning of the loop when the execution reaches the continue; stetment.