Friday, 10 January 2014

HTTP Request Lifecycle Events in IIS Pipeline

The life cycle of an ASP.NET application starts with a request sent by a browser to the Web server like IIS. If you are an ASP.NET developer who creates modules and handlers, it’s important to understand the the HTTP Request Lifecycle in IIS. This article will give you an overview of the order of events fired only in the 'Request Life Cycle' in IIS pipeline.
Note: In IIS 6.0, there are two request processing pipelines – one for native-code ISAPI filters and the other for managed applications like ASP.NET. However in IIS 7.0, there is one unified request processing pipeline for all requests. The ASP.NET runtime is integrated with the Web server. Also note that if IIS 7 is configured to work in Classic mode instead of Integrated mode, then it behaves like IIS 6.

When a request is made to IIS, it is queued in the application pool of the application. An application pool is a group of one or more URLs that are served by a worker process. The worker process(w3wp.exe) is responsible to forward the request to the application.
The request is processed by the HttpApplication pipeline and events are fired in the following order:
BeginRequest - The BeginRequest event signals the creation of any given new request. This event is always raised and is always the first event to occur during the processing of a request.
AuthenticateRequest - The AuthenticateRequest event signals that the configured authentication mechanism has authenticated the current request. Subscribing to the AuthenticateRequest event ensures that the request will be authenticated before processing the attached module or event handle.
PostAuthenticateRequest - The PostAuthenticateRequest event is raised after the AuthenticateRequest event has occurred. All the information available is accessible in the HttpContext’s User property.
AuthorizeRequest - The AuthorizeRequest event signals that ASP.NET has authorized the current request. You can subscribe to the AuthorizeRequest event to perform custom authorization.
PostAuthorizeRequest - Occurs when the user for the current request has been authorized.
ResolveRequestCache - Occurs when ASP.NET finishes an authorization event to let the caching modules serve requests from the cache, bypassing execution of the event handler and calling any EndRequest handlers.
PostResolveRequestCache – Reaching this event means the request can’t be served from the cache, and thus a HTTP handler is created here. A Page class gets created if an aspx page is requested.
MapRequestHandler - The MapRequestHandler event is used by the ASP.NET infrastructure to determine the request handler for the current request based on the file-name extension of the requested resource.
PostMapRequestHandler - Occurs when ASP.NET has mapped the current request to the appropriate HTTP handler
AcquireRequestState - Occurs when ASP.NET acquires the current state (for example, session state) that is associated with the current request. A valid session ID must exist.
PostAcquireRequestState - Occurs when the state information (for example, session state or application state) that is associated with the current request has been obtained.
PreRequestHandlerExecute - Occurs just before ASP.NET starts executing an event handler
ExecuteRequestHandler – Occurs when handler generates output. This is the only event not exposed by the HTTPApplication class.
PostRequestHandlerExecute - Occurs when the ASP.NET event handler has finished generating the output
ReleaseRequestState - Occurs after ASP.NET finishes executing all request event handlers. This event signal ASP.NET state modules to save the current request state.
PostReleaseRequestState - Occurs when ASP.NET has completed executing all request event handlers and the request state data has been persisted.
UpdateRequestCache - Occurs when ASP.NET finishes executing an event handler in order to let caching modules store responses that will be reused to serve identical requests from the cache.
PostUpdateRequestCache - When thePostUpdateRequestCache is raised, ASP.NET has completed processing code and the content of the cache is finalized.
LogRequest - Occurs just before ASP.NET performs any logging for the current request. The LogRequest event is raised even if an error occurs. You can provide an event handler for the LogRequest event to provide custom logging for the request.
PostLogRequest - Occurs when request has been logged
EndRequest - Occurs as the last event in the HTTP pipeline chain of execution when ASP.NET responds to a request. In this event, you can compress or encrypt the response.
PreSendRequestHeaders – Fired after EndRequest if buffering is turned on (by default). Occurs just before ASP.NET sends HTTP headers to the client.
PreSendRequestContent - Occurs just before ASP.NET sends content to the client.

Tuesday, 17 December 2013

Is-A Versus Has-A

Believe it or not, the concept of whether a class "Is a [something]" or "Has a [something]" comes up quite a bit in object oriented design. For instance, consider the questions "Is a transmission a car?" and "Does a car have a transmission?"

Clearly, the second question is the only of the two that one would answer in the affirmative. A transmission is not a car, but a car does have a transmission. This is a classic "Is-A/Has-A" example. And sometimes the answer to the questions are not so clear cut, particularly if the relationship is more obscure, like the relationship between a wall and sheetrock. For example, sheetrock, if hanged, could perform the duties of a wall, and a wall can contain sheetrock. The implementation of the solution to that question could probably be solved with either implementing a "Is-A" paradigm, or a "Has-A" paradigm.

So, I haven't described how "Is-A" and "Has-A" are implemented in object oriented design. Well the answer to that is really quite simple:

"Is-A" is implemented via INHERITANCE
"Has-A" is implemented via COMPOSITION

INHERITANCE

Inheritance is a good solution when some component would be logically defined, more abstractly, as another object.

For instance, think of fruit. Fruit is really more of an abstract concept than it is an implementation. Fruit can either have seeds (raspberries), or not have seeds (bananas). It can also have rind (bananas), or not have rind (raspberries). These attributes (seeds, rinds) are values that the more abstract "fruit" has.

The implementation of this code could be as follows:

///Below is the "Fruit" class

public class Fruit
{
private bool _hasSeeds;
private bool _hasRind;

///Public attribute for whether or not the fruit has seeds
public bool HasSeeds
{
get { return _hasSeeds; }
set { _hasSeeds = value; }
}

///Public attribute for whether the fruit has a rind
public bool HasRind
{
get { return _hasRind; }
set { _hasRind = value; }
}
}

///Public implementation of Banana
///Inherits from Fruit
public class Banana : Fruit
{
///Because the nature of a banana lends itself
///to knowing whether or not it has seeds and rind
///I will set those attributes in the constructor
///There is no reason that the class who calls
///Banana should have to know that a banana does not
///have seeds and does have a rind.
public Banana()
{
this.HasSeeds = false;
this.HasRind = true;
}

public void Peel()
{
///Do some kind of action to peel the banana
///Since Peel() is not common among all fruits
///Peel() does not have to be in the Fruit class
///However, there may be reasons to put it in there
///anyway. It depends on how similar the behavior
///is for all fruits' Peel() behavior
}
}

///Public implementation of Banana
///Inherits from Fruit
public class Raspberry : Fruit
{

///Like in Banana, raspberries HasSeeds and HasRind
///attributes are set
public Raspberry()
{
this.HasSeeds = true;
this.HasRind = false;
}
}


As you can see, this example lends itself very well to the "Is-A" paradigm, because clearly, Bananas and Raspberries are "Fruit." Also note that in the above, I did not put the Peel() method in the Fruit class, because it didn't seem to belong there. If I have an issue where many fruits need to have the Peel() behavior defined in them, I could do one of the following:

1. Create an interface, and have any peelable fruit invoke it:

public interface IPeelableFruit
{
///Notice how there is no implementation in the
///interface's Peel()
///This is because an interface has no implementation
///It is simply a public contract between anyone implementing it
void Peel();
}


Making an interface like the above would make a lot of sense if each fruit's implementation of Peel() were significantly different from one another.

With an interface, when I declare Banana, or any other peelable fruit, it would look like:

public class Banana : Fruit, IPeelableFruit
{
public void Peel()...
}


2. I could create a PeelableFruit class, and a NonPeelableFruit class, and have subsequent classes inherit:

public class PeelableFruit : Fruit
{
public PeelableFruit()
{
this.HasRind = true;
}
}


Then declare Banana as follows:

public class Banana : PeelableFruit
{
...
}


What would happen in the above example is: PeelableFruit would be a fruit. Banana would be ("is-a") a PeelableFruit, and also a Fruit, because it would inherit from both. The technical term is "inheritance chain".

COMPOSITION

"Has-A" lends itself to object relationships where something contains something else, like the above example of a Car and a Transmission. But, suppose we wanted to really define, in a fruit, what a "Rind" is. This would give us a pretty good example of "Has-A", because a PeelableFruit "Has-A" Rind.

So, if I wanted to build a "Rind" class, I would do something like the following:


public class Rind
{
private string _color;
//Let's say this is how difficult the rind is to peel
//A banana would be something like 2, and an orange would
//be 5
private int _difficultyToPeel;

private int _thicknessInMillimeters;

///Each of these private members would also have
///corresponding public members. I'll omit those

public Rind(string color, int difficultyToPeel, int thicknessInMillimeters)
{
_color = color;
_difficultyToPeel = difficultyToPeel;
_thicknessInMillimeters = thicknessInMillimeters;
}
}


So, now that the Rind class is defined, we can now put a Rind object into the PeelableFruit Class:


public class PeelableFruit : Fruit
{
///In the constructor, I instantiate the Rind object
///Otherwise, later on in the execution, I may forget
///and exceptions will get thrown
///Note the constructor had to be changed to facilitate
///the necessity to instantiate the Rind object
///(the color, difficulty, and thickness) parameters
public PeelableFruit(string rindColor, int difficultyToPeel, int thicknessInMillimeters)
{
this.HasRind = true;
this.PeelableFruitRind = new Rind(rindColor, difficultyToPeel, thicknessInMillimeters);
}

protected Rind PeelableFruitRind;
}


Then, when it comes time to instantiate a banana, doing so gives the banana much more robustness:

public class Banana : PeelableFruit
{
///I don't really know if this is "best practice"
///to make a class so knowing of how
///it implements a parent class, but I don't care.
///This is how I will continue
///to invoke this sort of inheritance
public Banana() : base("YELLOW", 2, 7)
{

}
}


Note that, when Banana gets instantiated, it will inherit the PeelableFruit's protected variable PeelableFruitRind, and that fruit rind will have a color of "YELLOW", a peeling difficulty of 2, and a thickness of 7 millimeters. Now, Banana "Has-A" rind, and that means it's using COMPOSITION.



Reference : http://www.c-sharpcorner.com/blogs/1416/is-a-versus-has-a.aspx

Monday, 16 December 2013

Eval() vs Bind()

Eval(): -

Eval() method provides only for displaying data from a data source in a control.


Bind():-

Bind() methods provides for two-way binding which means that it can be used to display as well update data from a data source

Thursday, 12 December 2013

Concatenate Rows using FOR XML PATH() IN SQL

'Concatenate Rows using FOR XML PATH() IN SQL


For example, if you have the following data:

USE AdventureWorks2008R2
SELECT      CAT.Name AS [Category],
            SUB.Name AS [Sub Category]
FROM        Production.ProductCategory CAT
INNER JOIN  Production.ProductSubcategory SUB
            ON CAT.ProductCategoryID = SUB.ProductCategoryID
image
The desired output here is to concatenate the subcategories in a single row as:
image
We can achieve this by using FOR XML PATH(), the above query needs to be modified to concatenate the rows:

USE AdventureWorks2008R2
SELECT      CAT.Name AS [Category],
            STUFF((    SELECT ',' + SUB.Name AS [text()]
                        – Add a comma (,) before each value
                        FROM Production.ProductSubcategory SUB
                        WHERE
                        SUB.ProductCategoryID = CAT.ProductCategoryID
                        FOR XML PATH('') – Select it as XML
                        ), 1, 1, '' )
                        – This is done to remove the first character (,)
                        – from the result
            AS [Sub Categories]
FROM  Production.ProductCategory CAT
Executing this query will generate the required concatenated values as depicted in above screen shot.

We can also use  FOR XML to convert out resulting table in to xml format.there are some other variants of 'FOR XML'.Try it...
Hope This Helps!

Tuesday, 3 December 2013

Unable to get value of the property 'toLowerCase': object is null or undefined






HOW-TO:
Open a modal RadWindow inside another RadWindow (or iframe) in IE9 and IE10 and avoid the JavaScript error this can cause because of a browser bug.

Note: This also applies to the server RadAlert(), RadConfirm() and RadPrompt() methods and the radopen(), radalert(), radconfirm() and radprompt() client-side methods when called from the server in the Sys.Application.Load event.

This can be solved by adding  a new method OnClientBeforeShow="fixIE" of
RadWindowManager


  <telerik:RadWindowManager ID="radWinManager"
            runat="server" DestroyOnClose="True" OnClientBeforeShow="fixIE"
            KeepInScreenBounds="true">
  </telerik:RadWindowManager>

Function

  function fixIE() {
       document.documentElement.focus();
    }


__doPostBack' is undefined in IE10

This bug occurs because of the missing of IE 10 browser definition files.This can be solved by installing hotfix for the ASP.NET browser definition files.

This hotfix introduces updated definitions in the browser definition file for Internet Explorer. The browser definition files are stored in one of the following folders, depending on the installed version of the Microsoft .NET Framework:
  • For 32-bit versions of the .NET Framework 2.0 SP2 or of the .NET Framework 3.5 SP1

    %WinDir%\Microsoft.NET\Framework\v2.0.50727\CONFIG\Browsers
  • For 64-bit versions of the .NET Framework 2.0 SP2 or of the .NET Framework 3.5 SP1

    %WinDir%\Microsoft.NET\Framework64\v2.0.50727\CONFIG\Browsers

For more information go to

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


Microsoft JScript runtime error: '$telerik' is undefined

This issue is encountered only when the property DestroyOnClose of the RadWindow is set totrue. If it is not needed in your scenario, I would suggest removing it.

Total Pageviews