Monday 25 July 2011

Differnce HttpModule , HttpHandler , HttpApplication??

HttpModule is a simple class implementing IHttpModule interface. This interface provides initialization and disposal events. Initialization is used to attache handlers to events which integrated pipeline raises (these are all the events that are exposed by the HttpApplication object – as BeginRequest and EndRequest), enabling HttpModule to work in IIS 7.0 Integrated mode.

HttpHandler requires (this is the one difference) to be mapped to a particular file extension – established through the web.config file - and needs an entry point to get into the handler’s code. This entry point is the HTTP endpoint – actually the last stop for the incoming Http requests – and is the other difference.

HttpApplication is a class implementing IHttpAsyncHandler and IHttpHandler (and another two) and is used as a base class for applications (most of the time as a base class of the Global class in Global.asax file). HttpApplication class are instantiated in the ASP.NET infrastructure and is not supposed to be created by the user directly.

Thursday 21 July 2011

Storing Data About a DataSet with the DataSet

While DataSets hold a lot of data, sometimes you want to keep track of information about the DataSet itself. You could store information about the dataset in some variable (e.g. the last time you checked the DataSet for changes) but it makes sense to me to store that information with the Dataset itself through its extended properties.

To add an extended property to a DataSet, you go the DataSet's ExtendedProperties collection and add a name and a value. This example adds a property called LastChecked to the ExtendedProperties collection with the current date and time:

Dim ds As New DataSet
ds.ExtendedProperties.Add("LastChecked", DateTime.Now)

To retrieve your extended property, just pass the name back to the DataSet's Item method. When you retrieve an item from this collection it comes back as an Object, so you'll need to convert the value when you retrieve it:

Dim stDate As String
Dim dtDate As DateTime

stDate = ds.ExtendedProperties("LastChanged")
If String.IsNullOrEmpty(stDate) = True Then
dtDate = DateTime.MinValue
Else
dtDate = Convert.ToDateTime(stDate)
End If

If dtDate < DateTime.Now AndAlso
ds.HasChanges = True Then
'... process DataSet
End If

Use of using keyword in C# (.Net)

here are three use of using keywords

1. using directive to use to import namespace in C# class
2. Create a using directive to use the types in a namespace withough having to specify that actual namespace (i.e. using directive creates an alias).
3. To automatically close and dispose any object references implementing the IDisposable interface


A using directive does not give you access to any of the various namespaces that might be nested in the namespace that you specified.

A user defined namespace is referring to any namespace you have created in your code.

Example For 2nd Point:

// using keyword
using System;
using CSF = SomeMain.Resource.ForCSharp; // alias

namespace SomeMain.Resource
{
public class MyClass
{
public static void Something()
{
//empty
}
}

namespace ForCSharp
{
public class MyNestedClass
{
public static void MyMessage()
{
System.Console.WriteLine("CSharpFriends!");
}

}

}

}
public class TestUsing
{
public static void Main()
{
CSF.MyNestedClass.MyMessage();

// pauses output window
Console.ReadLine();
}

}


Example 3rd Point:

using (SqlConnection cn = new SqlConnection(connectionString))
{
// do something
}

is the same as:

SqlConnection cn = new SqlConnection(connectionString)
try
{
// do something...
}
catch
{ }
finally
{
cn.Dispose();
}

Sunday 17 July 2011

Web sevices ISS 7.0

http://www.asp.net/general/videos/how-do-i-create-and-call-a-simple-web-service-in-aspnet
2 http://www.codeproject.com/KB/aspnet/IIS7ASPNet.aspx
3.http://krismanohar.com/blog/?p=34

http://www.dotnetfunda.com/forums/thread3683-how-to-host-webservice-in-iis7-.aspx