Sunday, August 17, 2008

A brief Tutorial about LINQ

LINQ (Language Intregated Query)
LINQ is a series of language extensions that supports data querying in a type-safe way. The data to be queried can take the form of XML (LINQ to XML), databases (LINQ-enabled ADO.NET, which includes LINQ to SQL, LINQ to Dataset and LINQ to Entities), objects (LINQ to Objects)
Before going to detail in LINQ, Let me tell you some intregal parts of LINQ:
1) Type Inference
Local type inference is a language feature that allows you to define variables and use them without worrying about their true type. Local type inference is also interchangeably known as implicitly typed local variables. The burden is put on the respective language compiler to determine the type of a variable by inferring it from the expression assigned to the variable. The result is type safety while allowing you to write more relaxed code, which is required to support Language Integrated Query (LINQ).Type inferred variables are strongly typed. The type cannot be changed once it is assigned as could be done with a variant type so it does not involve any casting operations or the resulting performance implications. A strong type is assigned, but simply done so by the compiler based on the results of the expression assigned to the variable.
A very basic example.
C# 2.0, you can write:
int i; i = 1;
C# 3.0,
you can also write this as:
var i = 1;
One More Example
var overdrawnQuery =
from account in accounts
where account.Balance < 0
select account ;
When the results of this query are iterated over using foreach, each element returned would consist of a name and address of an account that has a balance less than 0.

Thursday, August 7, 2008

Redirection in Update Panel Problem

ASP.NET Ajax, Update Panels and Response.Redirect

If your Response.Redirect doesn’t work under UpdatePanel’s callback, then you definitely missing ScriptModule in the web.config:

<httpModules>

<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>


</httpModules>
The ScriptModule is necessary to provide 3 features needed by the MS AJAX:

• To allow page redirection in a partial page update.
• To be able to call page methods instead of web service methods.
• To serve some files to the users skipping the standard authorization mechanism.

The ScriptModule handles three HttpApplication events:

• PreSendRequestHeaders
• PostAcquireRequestState
• AuthenticateRequest
As i discribe in last post.

The PreSendRequestHeaders event is raised before the server sends the headers to the browser, and it is the last chance to modify them. The ScriptModule handles this event, and checks if the current response code is 302, emitted when you call to the Response.Redirect method.

The ScriptModule fixes redirection problem, because when a redirect is found for a partial page update request, it clears the response (headers and content), maintaining the cookie collection and returning a string as the content of the response. The content of the response is obtained by calling the EncodeString method of an internal class called PageRequestManager.

One thing to point is that the ScriptModule checks if a rest call has generated a redirect, throwing and exception in that case. This is done for security reasons.

The PostAcquireRequestState event is raised after the session data has been obtained. If the request is for a class that implements System.Web.UI.Page and it is a rest method call, the WebServiceData class (that was explained in a previous post) is used to call the requested method from the Page. After the method has been called, the CompleteRequest method is called, bypassing all pipeline events and executing the EndRequest method. This allows MS AJAX to be able to call a method on a page instead of having to create a web service to call a method.

The AuthenticateRequest event is raised after the identity of the current user has been established. The handler for this event sets the SkipAuthorization property of the HttpContext for the current request. This property is checked in the authorization module to see if it has to omit authorization checking for the requested url. Usually an HttpModule use this property to allow anonymous access to some resources (for example, the Login Page if we’re using forms authentication). In our scenario, the ScriptModule sets the SkipAuthorization to true if the requested url is scriptresource.axd or if the authorization module is enabled and the request is a rest request to the authorization web service.

Wednesday, August 6, 2008

Http Handlers and Http Modules in Asp.net

HTTP modules and HTTP handlers are an integral part of the ASP.NET architecture. While a request is being processed, each request is processed by multiple HTTP modules (for example, the authentication module and the session module) and is then processed by a single HTTP handler. After the handler has processed the request, the request flows back through the HTTP modules. This article is divided into the following sections:
HTTP Modules
Available Events
Configuring HTTP Modules
Creating HTTP Modules
HTTP Handlers
Configuring HTTP Handlers
Creating HTTP Handlers
HTTP Modules
Modules are called before and after the handler executes. Modules enable developers to intercept, participate in, or modify each individual request. Modules implement the IHttpModule interface, which is located in the System.Web namespace.
Available Events
An HttpApplication class provides a number of events with which modules can synchronize. The following events are available for modules to synchronize with on each request. These events are listed in sequential order:
BeginRequest: Request has been started. If you need to do something at the beginning of a request (for example, display advertisement banners at the top of each page), synchronize this event.
AuthenticateRequest: If you want to plug in your own custom authentication scheme (for example, look up a user against a database to validate the password), build a module that synchronizes this event and authenticates the user how you want to.
AuthorizeRequest: This event is used internally to implement authorization mechanisms (for example, to store your access control lists (ACLs) in a database rather than in the file system). Although you can override this event, there are not many good reasons to do so.
ResolveRequestCache: This event determines if a page can be served from the Output cache. If you want to write your own caching module (for example, build a file-based cache rather than a memory cache), synchronize this event to determine whether to serve the page from the cache.
AcquireRequestState: Session state is retrieved from the state store. If you want to build your own state management module, synchronize this event to grab the Session state from your state store.
PreRequestHandlerExecute: This event occurs before the HTTP handler is executed.
PostRequestHandlerExecute: This event occurs after the HTTP handler is executed.
ReleaseRequestState: Session state is stored back in the state store. If you are building a custom session state module, you must store your state back in your state store.
UpdateRequestCache: This event writes output back to the Output cache. If you are building a custom cache module, you write the output back to your cache.
EndRequest: Request has been completed. You may want to build a debugging module that gathers information throughout the request and then writes the information to the page.The following events are available for modules to synchronize with for each request transmission. The order of these events is non-deterministic.
PreSendRequestHeaders: This event occurs before the headers are sent. If you want to add additional headers, you can synchronize this event from a custom module.
PreSendRequestContent: This event occurs when the Response.Flush method is called. If you want to add additional content, you can synchronize this event from a custom module.
• Error: This event occurs when an unhandled exception occurs. If you want to write a custom error handler module, synchronize this event.
Configuring HTTP Modules
The configuration section handler is responsible for configuring the HTTP modules within an application. It can be declared at the computer, site, or application level. Use the following syntax for the section handler:





Creating HTTP Modules
To create an HTTP module, you must implement the IHttpModule interface. The IHttpModule interface has two methods with the following signatures: void Init(HttpApplication);
void Dispose();

Saturday, July 26, 2008

I would like to tell you a tool set, calling to remote system api.
Tool set name is PSTools, very use full to work on remote system.
If you want execute a exe on remote system,want to know about services on the remote system and many more.Developer can use this utility from microsoft.
For More info: http://technet.microsoft.com/en-us/sysinternals/bb896649.aspx

Wednesday, May 28, 2008

Check this Out

Today while Internet surfing, i come to know a website which I want to share.
If you are programmer and want to refresh up your brain go and check out.
This site has some funny matter related to programming world and off course about programmer also like joke on programming, blog on .net, Some IT facts and many more
Check out this you will enjoy.
http://www.devtopics.com/

Saturday, May 3, 2008

ajax bridge call retry problem.

it was very hactic week,lot off work in office and in home also.
One problem i want to discribe here.
I am working in .net project.I was having a problem. Problem was like if suppose a application is calling a ajax service or call bia ajax.If that call fail than application give user to option to retry that call. We were not getting parameter info in onError event.than i found some solution micosoft Ajax book.syntax was like.
classname.MethodName(parameters,oncomplete,onerror,userContext,onTimeOut).
We were using bridge or u can say *.asbx using structre.
You can pass object in userContext variable.When ever call is succesfull of fail resultant method will get the userContext variaable.
There u can retry that method.
This is for this now.
keep programming.

Friday, April 25, 2008

Today i am strating my blog, obisiousally this is my first bolg.
From some time i were thinking about starting my blog but did not able to start.
Some days ago i read blog of Abhitabh bachan(Big B) and inspired from other places also, so i have decided to start my blog too.Today on saturday morning i got some time to create and i have done it.
I want to tell u about my self as i am a IT profesional working in good MNC.Offcourse i have to tell u my skill area also i am working in Microsoft technology like .net and all.

This is for today.
Keep smiling.


Please ignore spelling mistake .