-->

26/09/2011

Session Sharing


Scenario: In one of the projects, i got a situation where Half of the application is Migrated to MVC and other half is in Old 3 tier architecture.
Now, i have to host both the applications, and need to switch the context from one app to other with out intervening the user actions. We use to save all the user context and other information in sessions to maintain the state.
Bottom line is "I have to share the sessions between two different virtual directories in order to maintain the continuity of the application."


Resolution : After verifying couple of approaches, we found that Session can be shared by using a combination of  Custom Http Module  and SQL State management. We will see how to do that step by step.
Before going to Actual implementation, we need to see what are the tables used for SQL state management and their significance, thus we can understand how to make them work as we require.

Sql Server State Management: We know what are the different steps to do in order to configure SQL State management. Lets Open and see ASPState database. You will have 2 data tables.
             #1. ASPStateTempApplications - This used to create a unique Appid for each in-comming application request based on the unique application name/ application ID.
            #2. ASPStateTempSessions - This is used to create unique sessions for each user, correlated with each applicationid created in #1 table.


Logic: Now, from #1, you might have observed if you have 2 different applications, there will be 2 different application ids that will be created in table #1. So our duty is to restrict both the applications to create a single Appid, and this is acheived by using custom HTTP Module.

24/09/2011

How to create a Google's Doodle.







In this post we will see the basic development secret of most of the Google's Doodles.
Try rotating your cursor around the monster image.
That is nothing but a combination of Images , style sheets, and JQuery.

We will see step by step how to develop one.

Step 1: Get a Sprite Image. (Not a soft drink).
It is a technology of displaying multiple images using a single image. See the below image for example.
This is a single image file containing 18 different images. I am going to use only first nine on the left.

18/09/2011

WCF and MSMQ


We know Service and Client interact through EndPoints in WCF.












So clients send their request to the service and the service will receive them Via Endpoints. Thus the request will be processed.
Now, what if Service is down by the time client sends a request.
This is where Message Queuing (MSMQ) comes to picture to provide Message reliability. 

This article will describe how to Create / Test one, by providing step by step description. Before we start anything, go to Programs in control panel, open "Turn on/off windows componenets". There enable all the services pertaining to MSMQ. Also ensure that all the services pertaing to Message Queuing are started in services section.

Step 1: Objective
            I want to write a simple service (File Writer) which accepts user info from client and will write a log to a text file. And implement the message reliability using MSMQ.
Step 2: Create Service Contract.
           I defined a Interface for the file writer service. This interface is called "Contract", which will define the basic skeleton of the service.

13/09/2011

WCF Key Points


#1. In WCF Protocol Choice, Message Format, Encoding Format, Hosting Environment, Process Allocation etc, almost everything is configurable and hence called as loosely coupled.

#2. A WSDL (Web Service Description Language) file will define the following details of a WCF service.
  • Provides the information about the service contract and operations available.
  • Provides the information about all the end points exposed by the WCF service.
  •  Provides the information about the messages and types that can be exchanged between the client and the WCF service.
  •  WSDL also provides any information about the policies used.
 #3. Below are the advantages of defining the service contract at Interface level:
  • Defining service contracts using interfaces, removes coupling to service implementation. Later the implementation can be changed at will without affecting the clients.
  • Defining service contracts using interfaces, also allows a service to implement more than 1 contract. 

09/09/2011

View Controling in MVC.

We all know how View, Model, Controller communicates with each other.

















Everything a View expects is a Model object sent by controller. So, nothing else can effect the View.
So, what if you have a Grid View which has multiple columns and will display them based on certain roles.Keep in mind that View didn't support any CS files.

There are 2 ways of doing it.
1. Create separate Views and invoke them from controller based on the role.
2. Controlling the View by making Visibility matrix as a part of Model.(View Controling)

I believe APPROACH1 is not so appealing, as both the development cost and maintenance cost will be more with it.

So, i have chosen Approach2.

06/09/2011

Showing the views in Modal Popup in MVC


Showing a Modal popup using Jquery is nothing new.
The concept i like to stress on is how to display a View in that Popup.

Step 1: I have created a  View (Popup View). Make sure that you haven't selected any Layout page (Master), as we will b displaying it in the Popup.
Just for time being i embed some text in Popup View.
Step 2: Here in order to have ease of development, i have added a Telerik reference and using a telerik window. Place the below code for embedding the telerik window for accommodating your view.

@(Html.Telerik().Window() // Add Telerik.web.mvc.dll in references
    .Name("DetailWindow")
    .Title("PopUp View")
    .Draggable(true)
    .Modal(true)
    .Width(1190)
    .Scrollable(false)
    .Visible(false)   
    )

Step 3: Add the required script and CSS files to support the JQuery modal popup functionality.

03/09/2011

LINQ to SQL changes in .NET 4.0

Change list


Performance


  • Query plans are reused more often by specifically defining text parameter lengths (when connecting to SQL 2005 or later)
  • Identity cache lookups for primary key with single result now includes query.Where(predicate).Single/SingleOrDefault/First/FirstOrDefault
  • Reduced query execution overhead when DataLoadOptions specified (cache lookup considers DataLoadOptions value equivalency)

Usability


  • ITable<T> interface for additional mocking possibilities
  • Contains with enums automatically casts to int or string depending on column type
  • Associations can now specify non-primary-key columns on the other end of the association for updates
  • Support list initialization syntax for queries
  • LinqDataSource now supports inherited entities
  • LinqDataSource support for ASP.NET query extenders added

Page Controller Vs Front Controller Pattern

How do you best structure the controller for moderate / complex Web applications so that you can achieve reuse and flexibility while avoiding code duplication?

MVC has been a tried and tested method of structuring your applications for a long time. Generally MVC mainly focuses on separating model and view and less attention on the controller. Specially in rich client applications the view and the controller tends to lie close together. But in web applications this separation is more critical since the view is essentially happening at client side (browser) while the most of the controller sits in the server side.
There are 2 basic ways of structuring the 'C' of the MVC, i.e Controller. The 2 basic methods are the Page Controller method and the Front Controller method.

MVC Application Execution


The following table lists the stages of execution for an MVC Web project.
The respective class names will redirect to MSDN, for further reference.

Stage Details
Receive first request for the application In the Global.asax file, Route objects are added to the RouteTable object.
Perform routing The UrlRoutingModule module uses the first matching Route object in the RouteTable collection to create the RouteData object, which it then uses to create a RequestContext object.
Create MVC request handler The MvcRouteHandler object creates an instance of the MvcHandler class and passes the RequestContext instance to the handler.
Create controller The MvcHandler object uses the RequestContext instance to identify the IControllerFactory object (typically an instance of the DefaultControllerFactory class) to create the controller instance with.
Execute controller The MvcHandler instance calls the controller's Execute method.
Invoke action For controllers that inherit from the ControllerBase class, the ControllerActionInvoker object that is associated with the controller determines which action method of the controller class to call, and then calls that method.
Execute result The action method receives user input, prepares the appropriate response data, and then executes the result by returning a result type. The built-in result types that can be executed include the following: ViewResult (which renders a view and is the most-often used result type), RedirectToRouteResult, RedirectResult, ContentResult, JsonResult, FileResult, and EmptyResult.


Is it helpful for you? Kindly let me know your comments / Questions.