Wednesday, April 28, 2010

Prevent Page from being Cached in ASP.NET

In ASP.NET Page can be prevent from being cached by IIS. The following VB.NET code forces IIS to reprocess the page each time it's called.


Sub nocache_store()
'HttpContext.Current.Session.LCID = 2057
With HttpContext.Current
'.Session.LCID = 2057
.Response.AppendHeader("Pragma", "no-cache")
.Response.AppendHeader("Cache-Control", "no-cache")
.Response.AppendHeader("Cache-Control", "no-store")
.Response.AppendHeader("Cache-Control", "must-revalidate")
.Response.CacheControl = "no-cache"
.Response.Expires = -1
.Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache)
.Response.Cache.SetAllowResponseInBrowserHistory(False)
.Response.ExpiresAbsolute = New DateTime(1900, 1, 1)

End With
End Sub



click here to Convert Code from vb.net to c#.net

Copy table with data and structure in SQL


SELECT *
INTO new_table_name FROM old_tablename



above statement copy the table(existing table) data and structure into new table

Tuesday, April 20, 2010

Abstract Classes Vs Interface

Interface
An interface is a reference type containing only abstract members. These can be events, indexers, methods or properties, but only the member declarations. A class implementing an interface must provide the implementation of the interface members. An interface cannot contain constants, constructors, data fields, destructors, static members or other interfaces. Interface member declarations are implicitly public.


Abstract Class

Like an interface, you cannot implement an instance of an abstract class, however you can implement methods, fields, and properties in the abstract class that can be used by the child class.



* An Interface cannot implement methods.
* An abstract class can implement methods.


* An Interface can only inherit from another Interface.
* An abstract class can inherit from a class and one or more interfaces.


* An Interface cannot contain fields.
* An abstract class can contain fields.


* An Interface can contain property definitions.
* An abstract class can implement a property.


* An Interface cannot contain constructors or destructors.
* An abstract class can contain constructors or destructors.


* An Interface can be inherited from by structures.
* An abstract class cannot be inherited from by structures.


* An Interface can support multiple inheritance.
* An abstract class cannot support multiple inheritance.

For More help please follow...........

Monday, April 19, 2010

MD5 Password in Database(SQL Server 2005) itself

Some of us want some time to encrypt the password in database itself due to security reason.(i.e. At the time of user creation, forgot password or may be at the time of reset the password). So SQL Server also provide the utility for 'MD5 Algorithms' HashBytes() is the function used for encryption more on HashBytes()



select HashBytes('MD5','ABC123');


it will return the varbinary (maximum 8000 bytes)
the output will be '0xBBF2DEAD374654CBB32A917AFD236656'
but it will not equate the value with .NET hashing so to make it equal to .NET Hashing need to use another conversion function with triming the first to '0x'
characters from the returned value like:



select SUBSTRING(master.dbo.fn_varbintohexstr(HashBytes('MD5', 'ABC123')), 3, 32);



and the now the output is 'bbf2dead374654cbb32a917afd236656' that is equal to .NET Hashing techniques