Monday, December 28, 2009

Cookieless Forms Authentication

pass authentication ticket in querystrings

http://www.codeproject.com/KB/web-security/cookieless.aspx

Handling Application Error

http://www.beansoftware.com/ASP.NET-Tutorials/Application-Error-Http-Module.aspx

Custom Attributes

Here is a quote about what an attribute is all about:

"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:

http://www.codeproject.com/KB/dotnet/Custom_Attributes.aspx

WebService Best Practises



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

Interface vs Concrete classes design approach

http://lowrymedia.com/blogs/technical/interfaces-vs--concrete-classes/

MemberShips

http modules

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

Sunday, December 27, 2009

DataSet and Xml

public void XmlStringDataSet()
{
DataSet ds = new DataSet();
StringReader sr = null;
XmlTextReader xr = null;
XmlDocument xdoc = new XmlDocument();
xdoc.Load(@"C:\Documents and Settings\aakash\Desktop\toc.xml");
StringBuilder s = null;
sr = new StringReader(xdoc.InnerXml);
xr = new XmlTextReader(sr);
ds.ReadXml(xr);
foreach (DataTable t in ds.Tables)
{
Console.WriteLine("Table:" + t.ToString() + "\n");
foreach (DataRow r in t.Rows)
{
s = new StringBuilder();
foreach (DataColumn c in t.Columns)
{
s.Append(r[c]);
s.Append(" : ");
}
Console.WriteLine("Row: " + s.ToString() + "\n");
}
}
}

public string DataSetToXml()
{
DataSet ds = new DataSet();
ds.ReadXml(@"C:\Documents and Settings\aakash\Desktop\sample.xml");

XmlTextWriter x = null;
MemoryStream ms = null;
ms = new MemoryStream();
x = new XmlTextWriter(ms, Encoding.Unicode);
//Write dataset to writer
ds.WriteXml(x);
//Get the length of stream
int count=(int)ms.Length;
//get an array to read the stream
byte[] arr=new byte[count];
ms.Seek(0, SeekOrigin.Begin);
ms.Read(arr, 0, count);
//Use encoding
UnicodeEncoding utf = new UnicodeEncoding();
return utf.GetString(arr).Trim();

}




http://www.codeproject.com/KB/grid/DataSetToXml.aspx

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 vs. readonly

const and readonly perform a similar function on data members, but they have a few important differences.

[edit]

const

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]

readonly

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]

static

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]

MSDN references

§ Constants (C# Programming Guide)

§ const (C# Reference)

§ readonly (C# Reference)

§ static (C# Reference)

§ Static Classes and Static Class Members (C# Programming Guide)

Collection& Array Sorting

Array Sorting

static void Main(string[] args)
{
string[] a = new string[]
{
"Egyptian",
"Indian",
"American",
"Chinese",
"Filipino",
};
Array.Sort(a);
foreach (string s in a)
{
Console.WriteLine(s);
}
Console.ReadLine();
}
}

private static void ListSorting()
{
List list = new List();
list.Add("Hello");
list.Add("Z Hello");
list.Add("P Hello");
list.Add("Q Hello");
list.Add("A Hello");
list.Sort();
foreach (string s in list)
{
Console.WriteLine(s);
}
}

private static void ArrayListSorting()
{
ArrayList alist = new ArrayList();

alist.Add("Hello");
alist.Add("Z Hello");
alist.Add("P Hello");
alist.Add("Q Hello");
alist.Add("A Hello");
alist.Sort();
foreach (string s in alist)
{
Console.WriteLine(s);
}
ListSorting();
ArrayListSorting();
}


SQL 2005 features

http://www.microsoft.com/Sqlserver/2005/en/us/compare-features.aspx


primary Key Selection

Primary keys must be able to be quickly and easily generated and should not depend on other data for their generation. Because a record cannot be inserted in the database without a primary key, any violation in the generation of the primary key can result in loosing the data and not being able to insert the record. Therefore, the use of unique, automatically generated serial numbers is recommended for primary keys.

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.



http://databases.about.com/od/specificproducts/a/primarykey.htm

Acess Modifiers

http://www.c-sharpcorner.com/UploadFile/puranindia/WhatareAccessModifiersinCsharp08202009024156AM/WhatareAccessModifiersinCsharp.aspx



Acess Modifiers

http://www.c-sharpcorner.com/UploadFile/puranindia/WhatareAccessModifiersinCsharp08202009024156AM/WhatareAccessModifiersinCsharp.aspx

Parametrized properties

http://rbgupta.blogspot.com/2007/03/parameterized-properties-in-c.html

Anonymous Delegates

http://www.csharp-station.com/Tutorials/Lesson21.aspx

Saturday, December 19, 2009

DataSet minimum updates

http://www.codeproject.com/KB/grid/PartialUpdatesFromDataSet.aspx

Authentication Systems

Questions:-
Types
How do forms authentication actually works

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.




All authentication systems explained


Web Service Authentication

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



http://msdn.microsoft.com/en-us/library/aa738737.aspx