Friday, August 17, 2012

Install Maven Tool on Windows 7

Maven is a Java tool, so you must have Java installed in order to proceed. More precisely, you need a Java Development Kit (JDK), the Java Runtime Environment (JRE) is not sufficient.

Unzip the distribution archive, i.e. apache-maven-3.0.4-bin.zip to the directory you wish to install Maven 3.0.4. (Please download the latest Maven installation file from http://maven.apache.org/download.html site). My instructions assume you chose C:\Program Files\Apache Software Foundation. The subdirectory apache-maven-3.0.4 will be created from the archive.

Add the M2_HOME environment variable by opening up the system properties (WinKey + Pause), selecting the "Advanced" tab, and the "Environment Variables" button, then adding the M2_HOME variable in the user variables with the value C:\Program Files\Apache Software Foundation\apache-maven-3.0.4. Be sure to omit any quotation marks around the path even if it contains spaces. Note: For Maven < 2.0.9, also be sure that the M2_HOME doesn't have a '\' as last character.
In the same dialog, add the M2 environment variable in the user variables with the value %M2_HOME%\bin.

Optional: In the same dialog, add the MAVEN_OPTS environment variable in the user variables to specify JVM properties, e.g. the value -Xms256m -Xmx512m. This environment variable can be used to supply extra options to Maven.

In the same dialog, update/create the Path environment variable in the user variables and prepend the value %M2% to add Maven available in the command line.
In the same dialog, make sure that JAVA_HOME exists in your user variables or in the system variables and it is set to the location of your JDK, e.g. C:\Program Files\Java\jdk1.5.0_02 and that%JAVA_HOME%\bin is in your Path environment variable.

Open a new command prompt (Winkey + R then type cmd) and run mvn --version to verify that it is correctly installed.


Saturday, April 28, 2012

FAST Search Server 2010 for SharePoint: How to configure a Multiple server deployment.


This is an installation of FAST Search Server 2010 for SharePoint services on multiple servers.


When to use:


          • In most production environments, except small deployments without any fault-
             tolerance requirements. 


During configuration, one server is defined as the Administration server (This is the server where the administrative services are installed and run).


The deployment is scaled out by adding one or more Non-Administration servers. A non-administration server does not have the administrative services set up, but connects to a running administration server in a multiple server deployment. 


The non-administration server runs services such as query matching, indexing and document/item processing.


Follow below steps to configure;


Prepare the deployment file
Configure the administration server in a multiple server deployment
Verify all modules are running on the administration server
Configure non-administration server(s) in a multiple server deployment
Verify all modules are running on the non-administration server


Prepare the deployment file


Usage: 
This file specifies the distribution of components and services across servers in a FAST Search Server 2010 for SharePoint farm. 
For each FAST Search Server 2010 for SharePoint farm has separate deployment file and each server in the farm can read the deployment file and determine the services that run locally on that server. Each server also determines the location of other services that it communicates with.


Again this file is a required input parameter for run the configuration wizard (or configuration script) on the administration server in later steps. 
Because Non-administration servers will download the deployment file from the Administration server and determine which services should run on the local server, and start these services.


(Find example for a deployment.xml template directly under <FASTSearchFolder>\etc\, where <FASTSearchFolder> is the path of the folder where you have installed FAST Search Server 2010 for SharePoint, for example C:\FASTSearch).


Note: The completed deployment file to be used for the installation must be named 
          deployment.xml.


Deployment.xml template


Below template shows a multiple server deployment file, with three servers.




Configure the administration server in a multiple server deployment


This section describes how to configure a server as the administration server in a multiple server deployment by running the configuration wizard. The administration server must be configured and running before you can add one or more non-administration servers to the deployment.


Note: Follow below steps as a user who is a member of the local Administrators group.


  1. Prepare a deployment.xml file as described above sections.
  2. Run “Microsoft FAST Search Server 2010 for SharePoint Configuration Wizard.” (Navigation: Start -> Microsoft FAST Search Server 2010 for SharePoint Configuration Wizard).
  3. On the Welcome page, click Next.
  4. On the Select the deployment type page, select Admin server and then click Next.
  5. On the Enter the user name and password page, enter the user name and password for the FAST Search Server 2010 for SharePoint user. (Note: This user must be a domain user) 
  6. On the Enter a certificate password page, enter a certificate password of your choice. (Note: This password will be used to protect the general purpose FAST Search. You will need this password to install certificates on other servers). 
  7. Retype the password and then click Next.
  8. On the Server settings page, enter the fully qualified domain name of the server and the base port. In the Deployment file location box, enter the path of the deployment.xml file that you created. If there is an error in your deployment.xml file, you will get a warning. If no warnings or errors appear, your deployment.xml file syntax is correct. Click Next.(Note: Server name must be as the administration server that is defined in deployment.xml).
  9. On the Database settings page, enter the connection information to the SQL database that you installed and created before you installed FAST Search Server 2010 for SharePoint. Enter the Database connection string in the Format <ServerName>\<DBInstanceName>(Example: mysqlserver1.contoso.com\myinstance). Enter the Database name and Database port. The database will be created when you complete this configuration wizard. Click Next.
  10. On the Click-through relevancy settings page, add the desired relevancy click-through settings. Click-through relevancy enables automatic relevancy tuning based on how search users click on results. Select the relevant SharePoint Server 2010 installation type. If you have installed SharePoint Server 2010 using the Standalone option, specify the Fully Qualified Domain Name (FQDN) of the SharePoint Server 2010. If you have installed SharePoint Server 2010 using the Server Farm option, specify the user who is running the timer service in SharePoint Server 2010. This user is specified in the SharePoint Server 2010 post-setup configuration. If you do not want click-through relevancy, or if you do not have the necessary information, select Do not enable click-through relevancy. 
  11. Click Next.
  12. On the Configuration settings summary page, review the settings and then click Configure and wait while the configuration finishes.
  13. On the Post-setup configuration was successful page, click Finish. (Note: Before you restart the server, make sure that administrative permissions are defined. Update the local FASTSearchAdministrators group (which was created by the configuration wizard) to include either the user who will administer the FAST Search Server 2010 for SharePoint farm, or the domain group of your FAST Search Administrators.)
  14. Restart the server. 


Verify all modules are running on the administration server
  • Log in as a user who is a member of the local FASTSearchAdministrators group.
  • Navigate to Microsoft FAST Search Server 2010 for SharePoint.
  • Right-click Microsoft FAST Search Server 2010 for SharePoint shell and select Run as administrator.
  • At the Windows PowerShell command prompt, type the following command:“nctrl status”
  • Make sure that all modules have the status Running.

Configure the non-administration server(s) in a multiple server deployment


NOTE:  Before configuring non-administration servers, verify that all modules are running on the administration servers. 


On each and every non-administration server, do the following steps:  
  1. Log in as a user who is a member of the local Administrator group.(Note: Desktop navigation as follows: On the Start menu, right-click Microsoft FAST Search Server 2010 for SharePoint Configuration Wizard, and select Run as administrator.) and on the Welcome page, click Next.
  2. On the Select the deployment type page, select Non-admin server and then click Next.
  3. On the Enter the user name and password page, enter the user name and password for the FAST Search Server 2010 for SharePoint user. This must be the same user as you specified for the administration server during post-setup configuration.
  4. On the Enter a certificate password page, enter the certificate password. Use the password that was used for the certificate in the administration server post-setup configuration. Click Next.
  5. On the Server settings page, enter the fully qualified domain name of the server. Make sure that the server name is the same as the corresponding server name that is defined in deployment.xml.
  6. Enter the fully qualified domain name and the base port of the administration server and then click Next.
  7. On the Configuration settings summary page, review the settings and then click Configure and wait while the configuration finishes.
  8. On the Post-setup configuration was successful page, click Finish(Note: Before you restart the server, make sure that administrative permissions are defined. Update the local FASTSearchAdministrators group (which was created by the configuration wizard) to include either the user who will administer the FAST Search Server 2010 for SharePoint farm, or the domain group of your FAST Search Administrators.) 
  9. Restart the server. 




Verify that all modules are running on the non-administration server
  • Log in as a user who is a member of the local FASTSearchAdministrators group.
  • On the Start menu, click All Programs.
  • Click Microsoft FAST Search Server 2010 for SharePoint.
  • Right-click Microsoft FAST Search Server 2010 for SharePoint shell and select Run as administrator.
  • At the Windows PowerShell command prompt, type the following command:"nctrl status".
  • Make sure that all modules have the status Running.


Next step --> 
(Note: You have now completed the initial configuration of a multiple server deployment. To be able to crawl content by using the connector framework provided by SharePoint Server, Refer: “How to Create and set up the FAST Search Content Search Service Application (Content SSA) in FAST Search for SharePoint 2010”).

SharePoint 2010: Cant find "Publishing Approval" workflow template

To resolve this issue in SharePoint 2010, 


Navigate to Site Collection feature List in Site Collection level and Activate the feature named, "Publishing Approval Workflow".


(Note: Navigate the SharePoint site as follows, Site Actions --> Site Settings --> Site collection features)

Friday, April 27, 2012

FAST Search Server 2010 for SharePoint: How to configure a Stand-alone deployment


This article will guide you with step by step guidelines for configure a Stand – alone deployment by running the post – setup configuration wizard in a single server.


Prerequisites:  Install FAST Search Server 2010 for SharePoint.
                       (Reference: http://technet.microsoft.com/en-us/library/ff381243.aspx)


When to use:

  • In product evaluation or demonstrations, a small-scale deployment with minimal administrative overhead.
  • In development environment or test environment.

Installation steps to follow:
  1. Click on Start and run Microsoft FAST Search Server 2010 for SharePoint Configuration Wizard as local administrator.
  2. On the Welcome page, Click Next.
  3. On the Select the deployment type page, select Single server (Stand-alone) and then click Next.
  4. On the Enter the user name and password page, enter the user name and password for the FAST Search Server 2010 for SharePoint user. (Note: This user must be a domain user)
  5. On the Enter a certificate password page, enter a Certificate password of your choice. (Note: This password will be used to protect the general purpose FAST Search certificate. You will need this password to install certificates on other servers).
  6. On the Server settings page, enter the fully qualified domain name of the server and the base port. A deployment file will be generated automatically with all the settings configured. (Note: If you require a specific setup, you can create and use a custom deployment file)
  7. On the Database settings page, enter connection information to the SQL database that you installed and created before you installed FAST Search Server 2010 for SharePoint.
  8. Enter the Database connection string in the format <ServerName>\<DBInstanceName> (Example: mysqlserver1.contoso.com\myinstance).
  9. On the Click-through relevancy settings page, add the desired relevancy click-through settings. Select the relevant Microsoft SharePoint Server 2010 installation type and click Next                                                 (Note: If you have installed SharePoint Server 2010 using the Standalone option, specify the Fully Qualified Domain Name (FQDN) of the SharePoint Server 2010. If you have installed SharePoint Server 2010 using the Server Farm option, specify the user who is running the Microsoft SharePoint 2010 Timer Service. This user is specified in the SharePoint Server 2010 post-setup configuration.) If you do not want click-through relevancy, or if you do not have the necessary information, select Do not enable click-through relevancy. 
  10. On the Configuration settings summary page, review the settings and then click Configure.
  11. On the Post-setup configuration was successful page, click Finish.
  12. Restart the Server.


NOTE: How to verify that all modules are running?

  • Log in as a user who is a member of the local FASTSearchAdministrators group.
  • Navigate to Microsoft FAST Search Server 2010 for SharePoint.
  • Right-click Microsoft FAST Search Server 2010 for SharePoint shell and select Run as administrator.
  • At the Windows PowerShell command prompt, type the command, “nctrl status”.
  • Make sure that all modules have the status Running.



(Next Step: You have now completed the initial configuration of a stand-alone deployment. To be able to crawl content by using the connector framework provided by SharePoint Server, Refer: “How to Create and set up the FAST Search Content Search Service Application (Content SSA) in FAST Search for SharePoint 2010”).



Tuesday, April 17, 2012

How to Burn a CD/DVD on Windows Server 2008 R2


Install the Desktop Experience feature to add the Burn CD/DVD tab and several other tools from the Windows 7 client.

To install the Desktop Experience pack, follow below simple steps:

(1) Open Server Manager (Navigate: "Start" -> "Run" -> Type "servermanager.msc" and hit on "Enter").
(2) In the Features Summary section, click Add features.
(3) Select the Desktop Experience check box, and then click Next.
(4) Complete the wizard by clicking Install.

NOTE:

The Desktop Experience pack includes:

  • Windows Media Player
  • Desktop themes
  • Video for Windows (AVI support)
  • Windows SideShow
  • Windows Defender
  • Disk Cleanup
  • Sync Center
  • Sound Recorder
  • Character Map
  • Snipping Tool
  • Character Map
  • Snipping Tool

Thursday, February 23, 2012

Disk I/O error when I try to sign in to Skype?

Sometimes you may see a "Disk I/O error" when attempting to sign in to Skype.

To resolve this problem, please make sure that you are using the latest version of Skype.

However, if the same error happens again, follow these steps:

  1. Quit Skype. If you can see the Skype icon in the taskbar (at the bottom right of your screen), right-click it and select Quit. If you cannot see the Skype icon, use Task Manager to close Skype: press Ctrl+Alt+Delete and click Start Task Manager. In the Applications tab, select Skype and click End Task.
  2. Make sure that you can see hidden files.

    On Windows XP:

    1. In Windows Explorer, go to Tools > Folder Options.
    2. Click the View tab.
    3. Under Hidden files and folders, tick Show hidden files and folders, and then click OK.

    On Windows Vista / Windows 7/ Windows Server versions:

    1. Click Start > Control Panel > Appearance and Personalization > Folder Options.
    2. Click the View tab.
    3. Under Advanced settings, tick Show hidden files and folders, and then click OK.
  3. In Windows Explorer, navigate to the following folder:

    On Windows XP:

    • C:\Documents and Settings\\ApplicationData\Skype

    WindowsVista / Windows 7/ Windows Server versions::

    • C:\Users\\AppData\Roaming\Skype

    Where is your Windows user name.

  4. Locate the folder with the same name as your Skype Name and delete it.

    This will delete your chat history. To save your chat history, copy the file main.db and the “chatsync” folder to another location. You will be able to transfer them back (described in step 6, below). Please note that we cannot guarantee your entire chat history will be restored.

  5. Restart Skype and sign in with your Skype Name and password. If you forget your password,these instructions tell you what to do.
  6. The folder you have deleted will be recreated. If you saved your chat history files (described in step 4, above) transfer them back into the folder with the same name as your Skype name.

Monday, December 12, 2011

How to Connect Two Computers Without a Router?

Usage?

You can easily share an internet connection between the two machines or transfer photos, music and other files from one computer to another.

Things you need:

1. Inexpensive Ethernet crossover cable
2. Network cards (Also known as LAN or Ethernet cards) - should be installed on each of your computers.

How do you do this?

Step 1: Connect Computers with an Ethernet Crossover Cable.

Note: Before connecting the two computers with a physical cable, make sure that both machine are using the same work-group. Here is step-by-step guide that explains how you can change the workgroup of your computers.

Step 2: Changing workgroup

Open the Control Panel, type “Workgroup” in the search box, and select the entry that says “Change Workgroup Name.” Click the “Change…” button, enter a Work-group name and restart the computer.
Windows 7 users can skip one step; simply type “Workgroup” in the search box in the start menu, and select the first entry, then proceed as above.

Now that the workgroups are same for both computers, connect the two computers together using the Ethernet crossover cable. Simply plug-in one end of the crossover cable into the network adapter of Computer A and connect the other end of the cable to the network adapter of Computer B.

Windows will automatically recognize the new network, and you can now easily view files and folder that the other computer has shared. Simply open Networks from the Start Menu (or the Control Panel), and you should see the other computer by its name. You can then browse any shared files on the other computer, and can even utilize shared printers.

Step 3: Share an Internet Connection Between Two Computers

Open Control Panel, enter “network connections” in the search box on the top right and select “View Network Connections.”

Right-click on the network connection you wish to share (this must be the one connected to the internet) and select Properties. Select the "Sharing" tab and then check the option that says “Allow other network users to connect through this computer’s Internet connection.” Click OK, and the other computer you have connected to this Windows 7 or Vista computer should have internet access now.


Wednesday, February 16, 2011

How Web applications differ's from Websites?

For example, with a web application;

■ You can create an MVC application.
■ Visual Studio stores the list of files in a project file (.csproj or .vbproj), rather than
relying on the folder structure.
■ You cannot mix Visual Basic and C#.
■ You cannot edit code without stopping a debugging session.
■ You can establish dependencies between multiple web projects.
■ You must compile the application before deployment, which prevents you from testing
a page if another page will not compile.
■ You do not have to store the source code on the server.
■ You can control the assembly name and version.
■ You cannot edit individual files after deployment without recompiling.

Note:
Typically, website projects are the right choice when one developer will be creating and
managing a website.
Web application projects are better for enterprise environments with multiple developers and formal processes for testing, deployment, and administration.

Monday, December 13, 2010

Three-Tier Architecture Vs MVC



Three-Tier Architecture

Three-tier architecture is perfectly good for describing the overall design of a software product, but it doesn’t address what happens inside the UI layer. That’s not very helpful when, as in many projects, the UI component tends to balloon to a vast size, amassing logic like a great rolling snowball.

It shouldn’t happen, but it does, because it’s quicker and easier to attach behaviors directly to an event handler (a la Smart UI) than it is to refactor the domain model. When the UI layer is directly coupled to your GUI platform (Windows Forms, Web Forms), it’s almost impossible to set up any automated tests on it, so all that sneaky new code escapes any kind of rigor. Three-tier’s failure to enforce discipline in the UI layer means, in the worst case, that you can end up with a Smart UI application with a feeble parody of a domain model stuck on its side.

MVC Architecture

In this architecture, requests are routed to a controller class, which processes user input and works with the domain model to handle the request. While the domain model holds domain logic (i.e., business objects and rules), controllers hold application logic, such as navigation through a multistep process or technical details like authentication.

When it’s time to produce a visible UI for the user, the controller prepares the data to be displayed (the presentation model, or ViewData in ASP.NET MVC, which for example might be a list of Product objects matching the requested category), selects a view, and leaves it to complete the job. Since controller classes aren’t coupled to the UI technology (HTML), they are just pure application logic. You can write unit tests for them if you want to. Views are simple templates for converting the view model into a finished piece of HTML. They are allowed to contain basic, presentation-only logic, such as the ability to iterate over a list of objects to produce an HTML table row for each object, or the ability to hide or show a section of the page according to a flag on some object in the view model, but nothing more complicated than that. By keeping them simple, you’ll truly have the benefit of separating application logic concerns from presentation logic concerns.

Separating Out the Domain Model

Given the limitations of Smart UI architecture, there’s a widely accepted improvement that yields huge benefits for an application’s stability and maintainability.

By identifying the real-world entities, operations, and rules that exist in the industry or subject matter you’re targeting (the domain), and by creating a representation of that domain in software (usually an object-oriented representation backed by some kind of persistent storage system, such as a relational database or a document database), you’re creating a domain model.

What are the benefits of doing this?

• (Easy To Maintain) First, it’s a natural place to put business rules and other domain logic, so that no matter what particular UI code performs an operation on the domain (e.g., “open
a new bank account”), the same business processes occur.

• (No Source Code Duplications) Second, it gives you an obvious way to store and retrieve the state of your application’s universe at the current point in time, without duplicating that
persistence code everywhere.

• Third, you can design and structure the domain model’s classes and
inheritance graph according to the same terminology and language used by
experts in your domain, permitting a ubiquitous language shared by your programmers and business experts, improving communication and increasing the chance that you deliver what the customer actually wants (e.g., programmers working on an accounting package may never actually understand what an accrual is unless their code uses the same terminology).

In a .NET application, it makes sense to keep a domain model in a separate assembly (i.e., a C# class library project—or several of them) so that you’re constantly reminded of the distinction between domain model and application UI. You would have a reference from the UI project to the domain model project, but no reference in the opposite direction, because the domain model shouldn’t know or care about the implementation of any UI that relies on it.
For example, if you send a badly formed record to the domain model, it should return a data structure of validation errors, but would not attempt to display those errors on the screen in any way (that’s the UI’s job).

Wednesday, December 1, 2010

Can you find System.Web in add reference ? [.NET 4.0]

Today I was tried to use the method in "System.Web.HttpUtility.UrlEncode", but intelligence only shows three classes under System.Web.

After goggling I found that I need to add a .NET reference to "System.Web.dll" because I am making a Windows Application.

But unfortunately I could not find where is the "System.Web.dll" ? Its not available in the .NET references . :(

Finally figure out why is that! Yeah its because, I have targeted the Windows application to .NET framework4.0

But that's no an excuse I know;

Meanwhile I did further investigation of why it was not showing in the add reference tab of 4.0 project.

Yeah I got the issue, this is because, by default the project created in Framework 4.0 is defaulted to the profile.

Open the project properties and you can see it as shown below.

We can change this profile to .Net Framework 4.0 as shown below.

Once you have done this, you can go and add the reference to System.Web

Hope this helps!!!






Tuesday, November 30, 2010

What’s New in ASP.NET MVC 2

Since ASP.NET MVC 1 reached its final release in April 2009, the developer community has been hard at work applying it to every conceivable task (and a few inconceivable ones). Through experience, we’ve established best practices, new design patterns, and new libraries and tools to make ASP.NET MVC development more successful.
Microsoft has watched closely and has responded by embedding many of the community’s ideas into ASP.NET MVC 2. Plus, Microsoft noticed that certain common web development tasks were harder than expected in ASP.NET MVC 1, so it has invented new infrastructure to simplify these tasks.

Altogether, the new features in ASP.NET MVC 2 are grouped around the theme of streamlining
“enterprise-grade” web development. Here’s a rundown of what’s new:

• Areas give you a way to split up a large application into smaller sections (e.g., having a public area, an administrative area, and a reporting area). Each area is a separate package of controllers, views, and routing configuration entries, making them convenient to develop independently and even reuse between projects.

• Model metadata and templated view helpers are extensible mechanisms for describing the meaning of your data model objects (e.g., providing humanreadable descriptions of their properties) and then automatically generating sections of UI based on this metadata and your own design conventions.

• Validation is now far more sophisticated. Your model metadata can specify validation rules using declarative attributes (e.g., [Required]) or custom validators, and then the framework will apply these rules against all incoming data. It can also use the same metadata to generate JavaScript for client-side validation.

• Automatic HTML encoding (supported on .NET 4 only) means you can avoid cross-site scripting (XSS) vulnerabilities without remembering whether or not to HTML-encode each output. It knows whether you’re calling a trusted HTML helper, and will make the right encoding choice automatically.

• Asynchronous controllers are relevant if you must handle very large volumes of concurrent requests that each wait for external input/output operations (e.g., database or web service calls). These build on ASP.NET’s underlying IHttpAsyncHandler API, potentially boosting performance in such scenarios.

• HTTP method overriding is very neat if you’re exposing a REST-style interface to the Web with the full range of HTTP verbs such as PUT and DELETE. Clients that can’t issue these HTTP request types can now specify an override parameter, and then the framework will transparently accept that as the request’s HTTP verb.

• Strongly typed input helpers let you map input controls (e.g., text boxes or custom
templates) directly to your model objects’ properties with full IntelliSense and refactoring support.

• Child requests are a way to inject multiple extra independent sections into a page (e.g., a navigation menu or a “latest posts” list)—something that doesn’t otherwise fit easily into the MVC pattern. This is based on the RenderAction() mechanism previously included in the “MVC Futures” add-on for ASP.NET MVC 1.

Like any other version 2 product, there’s also a host of smaller improvements, including extra
extensibility options and performance optimizations. I will explain all the above areas one by one from my furture posts. Times up now!! Need to go to office.. catch u guys !! :)

ASP.NET Web Forms Vs ASP.NET MVC

You’ve already heard about the weaknesses and limitations in traditional ASP.NET Web Forms from my previous post (http://upulsgamage.blogspot.com/2010/11/whats-wrong-with-aspnet-web-forms.html). That doesn’t mean that Web Forms is dead, though;

Microsoft is keen to remind everyone that the two platforms go forward side by side, equally supported, and both are subject to active, ongoing development. In many ways, your choice between the two is a matter of development philosophy.

• Web Forms takes the view that UIs should be stateful, and to that end adds a
sophisticated abstraction layer on top of HTTP and HTML, using ViewState and postbacks to create the effect of statefulness. This makes it suitable for
drag-anddrop Windows Forms– style development, in which you pull UI widgets onto a canvas and fill in code for their event handlers.

• MVC embraces HTTP’s true stateless nature, working with it rather than
fighting against it. It requires you to understand how web applications actually work; but given that understanding, it provides a simple, powerful, and modern approach to writing web applications with tidy code that’s easier to extend and maintain over time, free of bizarre complications and painful limitations.

There are certainly cases where Web Forms is at least as good as, and probably better than, MVC. The obvious example is small, intranet-type applications that are largely about binding grids directly to database tables or stepping users through a wizard. Since you don’t need to worry about the bandwidth issues that come with ViewState, don’t need to be concerned with search engine optimization, and aren’t bothered about unit testing or long-term maintenance, Web Forms’ drag-and-drop development strengths outweigh its weaknesses.

On the other hand, if you’re writing applications for the public Internet, or larger intranet
applications (e.g., more than a few person-month’s work), you’ll be aiming for fast download speeds and cross-browser compatibility, built with higher-quality, well-architected code suitable for automated testing, in which case MVC will deliver significant advantages for you.

Saturday, November 27, 2010

Who Should Use ASP.NET MVC?

As with any new technology, its mere existence isn’t a good reason for adopting it (despite the natural tendencies of software developers). Let’s consider how the MVC Framework compares with its most obvious alternatives.

Comparisons with ASP.NET Web Forms
You’ve already heard about the weaknesses and limitations in traditional ASP.NET Web Forms from my previous post, and how ASP.NET MVC overcomes many of those problems. That doesn’t mean that Web Forms is dead, though; Microsoft is keen to remind everyone that the two platforms go forward side by side, equally supported, and both are subject to active, ongoing development.

In many ways, your choice between the two is a matter of development philosophy.

• Web Forms takes the view that UIs should be stateful, and to that end adds a
sophisticated abstraction layer on top of HTTP and HTML, using ViewState and
postbacks to create the effect of statefulness. This makes it suitable for drag-anddrop
Windows Forms–style development, in which you pull UI widgets onto a
canvas and fill in code for their event handlers.

• MVC embraces HTTP’s true stateless nature, working with it rather than fighting
against it. It requires you to understand how web applications actually work; but
given that understanding, it provides a simple, powerful, and modern approach to
writing web applications with tidy code that’s easier to extend and maintain over
time, free of bizarre complications and painful limitations.

There are certainly cases where Web Forms is at least as good as, and probably better than, MVC.
The obvious example is small, intranet-type applications that are largely about binding grids directly to database tables or stepping users through a wizard. Since you don’t need to worry about the bandwidth issues that come with ViewState, don’t need to be concerned with search engine optimization, and aren't bothered about unit testing or long-term maintenance, Web Forms’ drag-and-drop development strengths outweigh its weaknesses. On the other hand, if you’re writing applications for the public Internet, or larger intranet applications (e.g., more than a few person-month’s work), you’ll be aiming for fast download speeds and cross-browser compatibility, built with higher-quality, well-architected code suitable for automated
testing, in which case MVC will deliver significant advantages for you.

What’s Wrong with ASP.NET Web Forms?

Traditional ASP.NET Web Forms was a fine idea, and a thrilling prospect at first, but of course reality turned out to be more complicated. Over the years, real-world use of Web Forms uncovered a range of weaknesses:

• ViewState weight:
The actual mechanism of maintaining state across requests(ViewState) often results in giant blocks of data being transferred between client and server. It can reach hundreds of kilobytes in many real-world applications, and it goes back and forth with every request, frustrating site visitors with a long wait each time they click a button or try to move to the next page on a grid.
ASP.NET AJAX suffers this just as badly,1 even though bandwidth-heavy page updating is one of the main problems that Ajax is supposed to solve.

• Page life cycle:
The mechanism of connecting client-side events with server-side event handler code, part of the page life cycle, can be extraordinarily complicated and delicate. Few developers have success manipulating the control hierarchy at runtime without getting ViewState errors or finding that some event handlers mysteriously fail to execute.

• False sense of separation of concerns:
ASP.NET’s code-behind model provides a means to take application code out of its HTML markup and into a separate codebehind class. This has been widely applauded for separating logic and presentation, but in reality developers are encouraged to mix presentation code
(e.g., manipulating the server-side control tree) with their application logic (e.g., manipulating database data) in these same monstrous code-behind classes. Without better separation of concerns, the end result is often fragile and unintelligible.

• Limited control over HTML:
Server controls render themselves as HTML, but not necessarily the HTML you want. Prior to version 4, their HTML output usually failed to comply with web standards or make good use of CSS, and server controls generated unpredictable and complex ID values that are hard to access using JavaScript. These problems are reduced in ASP.NET 4.

• Leaky abstraction:
Web Forms tries to hide away HTML and HTTP wherever possible. While trying to implement custom behaviors, you’ll frequently fall out of the abstraction, forcing you to reverse-engineer the postback event mechanism or perform perverse acts to make it generate the desired HTML. Plus, all this abstraction can act as a frustrating barrier for competent web developers. For
example, rich client-side interactivity is made excessively difficult because all client-side state can be blown away at any moment by a postback.

• Difficulty applying automated tests:
When ASP.NET’s designers first set out their platform, they could not have anticipated that automated testing would become the mainstream part of software development that it is today. Not surprisingly, the tightly coupled architecture they designed is totally unsuitable for unit testing. Integration testing can be a challenge too, as I’ll explain in within next few days.