Wednesday 30 January 2013

Mixing ASP.NET webforms and ASP.NET MVC


In early years, I mean, before Microsoft release ASP.NET MVC framework, all of our applications has built in ASP.NET webforms. 

After ASP.NET MVC arrives and we start tasting(using) the framework then everyone start building and migrating existing applications into ASP.NET MVC as ASP.NET MVC giving more flexible options than webforms.

So for example, all rooms (say each room is our application) in our house are built in ASP.NET webforms.  We can destroy the whole house and re build from scratch using ASP.NET MVC.

But in the business perspective, we cannot do that as many of our systems may be making money and depends upon other factors such as internal and external systems may be interconnected and using same resources…etc.

So we need renovate or rebuild our rooms one by one and find the alternative place to stay within our house without vacating from existing house until rebuild or renovate the whole house.

You may be think, why do we need such a story here and should not come to the relevant problems straightway to talk about?

That is good question. Because this story may be make you think more in different angles and we never forget any concept when we talk about with some real time stories.

Let’s say we renovated some of the rooms using ASP.NET MVC and we need to share the resources all across the rooms until rebuild/renovate the whole house.

I mean technically, how we can reuse the many features and resources among the two applications.
Particularly, session, cookies, HTTPContext and server objects…etc.

Before getting into this topic further deep, I have Bing and Google it and found the very interesting article on http://www.packtpub.com/article/mixing-asp.net-webforms-and-asp.net-mvc?page=1&signup=false

 What are the key considerations when mixing ASP.NET webforms into ASP.NET MVC?
  1. We can either mix ASP.NET MVC into ASP.NET webforms or ASP.NET web forms into ASP.NET MVC.  Mixing ASP.NET webforms into ASP.NET MVC is less overhead and its depends upon your complexity of your ASP.NET webforms or ASP.NET MVC applications. Some cases reverse should be less overhead.
  2. We need to add/modify Global.asax.cs if your ASP.NET application has events on that.
  3. We need to add/remove few configuration settings & assemblies,  3rd party(if you using it in your ASP.NET webforms application)  assemblies settings into Web.config
  4. We may need to add/modify changes in some of the code behind files in order to build with your current .NET framework. I don’t think so you need do many changes apart from this.
The above solution will work until we renovate or rebuild the whole house without vacating the house.

Please feel free to share your views/thoughts and contact me if you have any questions.

Thanks for reading.

1 comment:

  1. Thanks Jay. Nice articles. We need to consider to SSO to pass login credentials between web sites of ASPX and MVC projects. But using SSO will be an issue if Cookies disabled in the client side. We can handle by maintaining our own session using DB by encryption/decryption with salt key by passing session key between web sites. One more option using SessionState with connecting DB instead of using StateSession or InProc.

    But as you said easiest way to share session will be merging ASPX/MVC projects depends upon complexity of both ASPX and MVC projects. In my experience its not that easy.

    One more good information, good on you Jay. Please keep rocking.

    ReplyDelete