Monthly Archives: July 2012

ASP.NET 4.0 Features

1) Output Cache Extensible

ASP.Net 1.0 introduced the concept of Output Caching, which enable developers to store generated output of pages/controller (MVC)/HTTP response in an in-memory cache.

So on subsequent request, ASP.Net retrieves the output from the cache instead of regenerating from scratch. This dramatically improved the performance of the application.

ASP.Net output caching is flexible enough to enable cache different version of content based on query string/form-post parameters.

Also enable to cache different version based on browser type or user-language. Like to have different versions of page for mobile.

Limitation:- From ASP.Net1.0 to 3.5 is that cache store is not extensible i.e. always have to be stored in an in-memory.

Solution:- ASP.Net 4 Output Cache Extensible.

Now enables developers to configure more custom output-cache providers like local/remote disk, database, cloud etc.

To create custom output-cache provider,

1) a class which derived from System.Web.Caching.OutputCacheProvider has to be created, whic involve overriding 4 public methods to provide implementation for adding/removing/retrieving/updating.

2) Also the output-cache provider has to be configured in web.config.

 

 

 

 

 

 

 

 

 

 

2) Session State Compressor

Advertisements

Leave a comment

Filed under ASP.Net

Contracts in WCF

WCF Contracts
There are basically four types of contracts:-
1) Service Contracts
It define what operation the client can perform using the Service. There are two types of Service contracts
a) ServiceContract – This attribute defines Interface.
b) OperationCOntract – This attribute defines method of Interface.

2) Data Contract
It defines the data types passed to and from the service. There are two types again:
a) DataContract – This attribute defines the data class.
b) DataMembers – This attribute defines the properties.
If DataMember attributes are not specified for a properties in the class, that property can’t be passed to-from web service.

3) FaultContract
It defines which type of error will be raised by the Service.

4) Message Contract
It allows service to interact directly with Message. Message Contract can be types or untyped.

Leave a comment

Filed under WCF

WCF Security & Types

There are two types of Security implemented in WCF:
Transport LevelĀ  :- It means securing the meadiums on which data travels.
Message Level :- It means securing the actual data packets sent by WCF.

Transport median (like HTTP, TCP, MSMQ etc) itself provide security features like HTTP can have SSL security (HTTPS).

Message security is provided using WS-Securities like message encrypted using encryption algo, message encrypted using X-509 certificate, message protected using username/password.

WCF gives option to either use Message/Transport level security standalone or combination of both.

We will implement combination of both below.

Step 1:- Customize WsHttp binding with Security mode & Credential Type
Configure wsHttp binding with Security Mode & Credential Type. There are three options for security mode i.e.
Transport,
Message &
TransportWithMessageCredential

Now as we are implementing dual security so we will use TransportWithMessageCredential mode where Transport level security is provided by SSL & Message security is provided by Username-Password.
Secondly CredentialType needs to be provided out of
none,
windows,
username,
certificate &
issued token

We will be using CredentialType as username.
Below are the changes done in web.config:

<bindings>
<wsHttpBinding>
<binding name=”Binding1″>
<security mode=”TransportWithMessageCredential”>
<message clientCredentialType=”UserName” />
</security>
</binding>
</wsHttpBinding>
</bindings>

Step 2:- Create Custom Validator Class
After customizing wsHttp binding, we need to create custom validator class for authentications.
To create the custom validator class you need to inherit it from “UserNamePasswordValidator” class & override Validate() method.

class MyValidator : UserNamePasswordValidator
{
protected override void Validate(string userName, string password)
{
if(userName==”Dev” && password=”pass123″)
{
//
}
else
{
throw new FaultException(“Invalid Credentials”);
}
}
}

The faultException is handled by WCF client if the credentials are not valid.

Step 3:- Define Runtime behavior.
Now we need to execute MyValidator class for the Username provided inthe WCF service by WCF client. So for this we add behavior

<behaviors>
<serviceBehaviors>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode=”Custom”
customUserNamePasswordValidatorType=”MyValidator” />
</serviceCredentials>
</serviceBehaviors>
</behaviors>

Step-4 :- Define SSL for your WCF Service
Step 5:- Consume WCF service
Step 6:- Run WCF Service
Above three steps are explained in below link
http://www.dotnetfunda.com/articles/article891-6-steps-to-implement-dual-security-on-wcf-using-user-name-ssl.aspx

Leave a comment

Filed under WCF

Page Life Cycle

Below are the events:

Page_PreInit (EventArgs e)

UC_Init (EventArgs e)
CWebC_Init (EventArgs e)
Master_Init (EventArgs e)
Page_Init (EventArgs e)

UC_TrackViewState ()
CWebC_TrackViewState ()
Master_TrackViewState ()
Page_TrackViewState ()

Page_Load (EventArgs e)
Master_Load (EventArgs e)
UC_Load (EventArgs e)
CWebC_Load (EventArgs e)

Page_PreRender (EventArgs e)
Master_PreRender (EventArgs e)
UC_PreRender (EventArgs e)
CWebC_PreRender (EventArgs e)

Page_SaveViewState()
Master_SaveViewState()
UC_SaveViewState()
CWebC_SaveViewState()

Page_Render(HtmlTextWriter writer)
Master_Render(HtmlTextWriter writer)
UC_Render(HtmlTextWriter writer)
CWebC_Render(HtmlTextWriter writer)

UC_UnLoad()
CWebC_UnLoad()
Master_UnLoad()
Page_UnLoad()

Leave a comment

Filed under C#

try/catch/finally nested

We can have try..catch..finally nested in try/catch/finally blocks:

Leave a comment

Filed under C#