Monday, December 28, 2009
Cookieless Forms Authentication
Custom Attributes
"Attributes provide a powerful method of associating declarative information with C# code (types, methods, properties, and so forth). Once associated with a program entity, the attribute can be queried at run time and used in any number of ways." - MSDN
Attributes are classes that allow you to add additional information to elements of your class structure.
The information from the attribute can later be obtained by using Reflection. See article on reflection on this site. In this article, we will show you how to add stereotypes to your method. A stereotype is a way to describe a specific category for a design element and is a term that comes from UML. Our stereotype attribute provides two strings to describe our methods, a stereotype string and a description string. Below is the code for declaring our custom attribute, stereotype:
Sunday, December 27, 2009
DataSet and Xml
Monday, December 21, 2009
Early and Late Binding
Binding refers the object type definition. You are using Early Binding if the object type is specified when declaring your object. Eg if you say Dim myObject as ADODB.Recordset that is early binding(VB example).
If on the other hand you declare your object as a generic type you are late binding. Eg if you Dim myObject as Object (VB example).
One should note that binding is determined at object declaration and not at object instantiation. Therefore it does not matter if you later go on to Set myObject = New ADODB.Recordset or Set myObject = CreateObject(”ADODB.Recordset”).
Early binding allows developers to interact with the object’s properties and methods during coding. You can enjoy the benefits of intellisense. Also, early binding permits the compiler to check your code. Errors are caught at compile time. Early binding also results in faster code. It’s disadvantage is that you cannot create a generic object which may be bound to different types of objects.
Late binding on the other hand permits defining generic objects which may be bound to different objects. Eg you could declare myControl as Control without knowing which control you will encounter. You could then query the Controls collection and determine which control you are working on using the TypeOf method and branch to the section of your code that provides for that type. This is the only benefit of late binding. It’s disadvantages are that it is error prone and you will not enjoy much intellisense whilst coding.
const vs readonly
Within a class, const, static and readonly members are special in comparison to the other modifiers.
[edit]
const and readonly perform a similar function on data members, but they have a few important differences.
[edit]
A constant member is defined at compile time and cannot be changed at runtime. Constants are declared as a field, using the constkeyword and must be initialized as they are declared. For example;
public class MyClass
{
public const double PI = 3.14159;
}
PI cannot be changed in the application anywhere else in the code as this will cause a compiler error.
Constants must be of an integral type (sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal,bool, or string), an enumeration, or a reference to null.
Since classes or structures are initialized at run time with the new keyword, and not at compile time, you can't set a constant to a class or structure.
Constants can be marked as public, private, protected, internal, or protected internal.
Constants are accessed as if they were static fields, although they cannot use the static keyword.
To use a constant outside of the class that it is declared in, you must fully qualify it using the class name.
[edit]
A read only member is like a constant in that it represents an unchanging value. The difference is that a readonly member can be initialized at runtime, in a constructor as well being able to be initialized as they are declared. For example:
public class MyClass
{
public readonly double PI = 3.14159;
}
or
public class MyClass
{
public readonly double PI;
public MyClass()
{
PI = 3.14159;
}
}
Because a readonly field can be initialized either at the declaration or in a constructor, readonly fields can have different values depending on the constructor used. A readonly field can also be used for runtime constants as in the following example:
public static readonly uint l1 = (uint)DateTime.Now.Ticks;
Notes
§ readonly members are not implicitly static, and therefore the static keyword can be applied to a readonly field explicitly if required.
§ A readonly member can hold a complex object by using the new keyword at initialization.
§ readonly members cannot hold enumerations.
[edit]
Use of the static modifier to declare a static member, means that the member is no longer tied to a specific object. This means that the member can be accessed without creating an instance of the class. Only one copy of static fields and events exists, and static methods and properties can only accessstatic fields and static events. For example:
public class Car
{
public static int NumberOfWheels = 4;
}
The static modifier can be used with classes, fields, methods, properties, operators, events and constructors, but cannot be used with indexers, destructors, or types other than classes.
static members are initialized before the static member is accessed for the first time, and before the static constructor, if any is called. To access a staticclass member, use the name of the class instead of a variable name to specify the location of the member. For example:
int i = Car.NumberOfWheels;
[edit]
§ Constants (C# Programming Guide)
§ Static Classes and Static Class Members (C# Programming Guide)
Collection& Array Sorting
primary Key Selection
Each record (row) must be uniquely identified within the table.
Primary keys cannot be modified or updated throughout the life of the database. If the primary key must be updated because it was not selected properly, the entire row must be deleted and recreated. If the record has dependent records or children in other tables, which have children in other tables, deleting the record is an affair by itself. So encoding meanings in the value of the primary key is a dangerous practice that must be discontinued. For example the following candidate for identifying a citizen is not valid: the first three characters encode the city of residence, the next three digits encode the religion and the last seven digits are the unique home telephone number. All pieces of this candidate key are subject to change.
Saturday, December 19, 2009
Authentication Systems
Introduction
Forms Authentication is a mechanism to allow only authenticated user with valid credential to view a particular page or group of pages/folders and stop unauthenticated or anonymus use outside the secure boundry. Forms authentication uses an authentication ticket that is created when a user logs on to a site, and then it tracks the user throughout the site. The forms authentication ticket is usually contained inside a cookie. However, cookieless forms authentication is also possible that works by passing user ticket in query strings.
Thursday, December 17, 2009
Saturday, December 12, 2009
Friday, December 11, 2009
Thursday, December 10, 2009
DataContracts vs XmlSerializer
| Points | XmlSerializer | DataContracts | |
| Control over Types | Strong | Loose | |
| | | | |
| Optimization & Performance | Ok | Good by 10 times | |
| | | | |
| Shows Serialized or not are serialized into XML | No | Yes | |
| | | | |
| Translate | Public props | Regardless of the access modifiers | |
| | | | |
| Restrictions | Hashtable that implement the IDictionary interface | No | |
| | | | |
| Fully trusted code accesses all resources on your machine. | Not | DataContractSerializer being able to access the non-public members of a type is that it requires full trust | |
| | | | |
| | | DataContractSerializer incorporates some support for versioning | |
| | | | |
| | | | |