Sunday, November 23, 2008

ASP.NET MVC Routing Using XML Custom Configuration Settings

In ASP.NET MVC application, you need to add some routing code in the Application_Start of the Global.asax file to define your routing criteria. These lines of code take a shape of configuration settings for the MVC application and I was thinking if we can transfer these configurations line of codes to be XML settings in the web.config file. My target is to make the routing configuration in the web.config file as following:

As you can see, the later configurations define the Ignore and Routing lists of the MVC application. In the "Ignore" list, you define the URL criteria to be ignored by the MVC routing. In the "Map" list, you specify a list of the routes including the route name, controller and action. You can also define any optional parameter mappings for your actions.

To do that, I have to create a custom configuration section: MvcRouteConfigurationSectin. The section has a IgnoreCollection - inherited from ConfigurationElementCollection class - of IgnoreItem and another RoutingCollection of RouteItem.

The solution will also add an extension method for RouteCollection object so that you will be able to map the configuration section in the web.config directly to your RouteTable.

To use the project, you just need to include the MvcXmlRouting.dll in your MVC web project. Then you add the following line inside the configSection Tag in web.config:

You then define the ignore and the routing configurations for your web application as defined earlier in the web.config. Finally, you will need to edit the RegisterRoutes method in the Global.asax file to add a couple of lines as following:

Now all your routing configuration will go to the web.config file. No need to edit the Global file anymore. However, changing the routes in the web.config still need to reset your IIS as the routing is registered in Application_Start.

Download: Binary | Source Code

The project is implemented using ASP.NET MVC Beta 1 and Visual Studio 2008. It's not guaranteed that this project or the related assemblies will properly work in earlier or newer version of ASP.NET MVC Framework.

kick it on
DZone - Vote Up!

Ping Back Links:

Thursday, November 13, 2008

Hewitt Middle East Best Employer Study

In the last December 2007, this blog hosted a quick survey to measure the different aspects of the software employers inside Egypt. I am glad to announce that there is another independent initiative showing up these days. Hewitt - a provider of HR outsourcing and consulting services - launches the Best Employers in Middle East 2009 study. The study aims to honor the leading organizations of Middle East as outstanding places to work. Hewitt conducts its Best Employer research in a number of markets, including Eastern Europe, Canada, Latin America and Asia. This survey is designed to be the largest employee research project ever undertaken in Middle East. Hewitt invites all the employers in the Middle East to participate in this survey. The survey will show how effective is your organization and wither it provides a workplace that engages the intellectual and emotional commitment of your employees or not. The study will provide a level of confidentiality so that the names of all participating organizations will be strictly confidential at all points of time. The exception will be those organizations that will be honored as a Hewitt Best Employer in Middle East.

Wednesday, November 12, 2008

On Finding the Arabic Needle in the e-Haystack

Lack of information is an issue, but lack of ability to reach the information is a much more serious issue. With internet getting appended everyday with million of new information pages, search engines become unconsciously mandatory to use.

CuttingEdgeClub organize a seminar in ITWorx to elaborate how search engines operates and to highlight the status of the rapidly growing Arabic-Web in particular.

The seminar is scheduled to be on Wednesday, 19th November, 2008 at 5:30 PM in ITWorx - Free Zone. The session will be provided by Hany Abdelkawi - Project Manager, Link Development.

CuttingEdgeClub is an ITWorx Club aims to share information about the latest technologies among the IT community by organizing technical sessions and seminars in a regular base.

Saturday, November 08, 2008 9th Gathering - Coming Out This November announced the next 9th Gathering to be held in 29th November. The event will be in CIC - Canadian International College and four speakers from ITWorx and Raya Software will be giving the sessions. Here is the list of the topics and speakers:

BizTalk - SharePoint Integration.
Hossam El-Deen M. Barakat
Senior Software Developer | Raya Software
Information Architecture
Mostafa Mourad
Team Leader | ITWorx

Hossam Kamel
Senior Software Engineer | ITWorx

Applying Domain Driven Design on ASP.NET MVC
Mohammed Meligy
Senior Software Developer | Raya Software user group is a group of youth who share the same passion for the development on .Net platform in Egypt. The group started in the last December 2007 with a total of eight technical events during the last 10 months. For more information about the group, visit their website here.

PRG Pattern - You're Already Doing it

Have you ever had this message dialog asking about resubmiting the data when you try to refresh a web page? This actually happen after submitting a form or enter your login information.

One of the good practices when developing web application is to redirect the user after a successful posting request. This practice is refereed as PRG pattern (Post/Redirect/Get). The target is to avoid duplicate post requests from the client and providing a smooth navigation through the web application.

What actually happen in PRG is that the browser try to send an HTTP 303 redirect request along with HTTP "Location" header. It's nice to know that something you're used to make as a default practice is actually a pattern. The following is a sample code in ASP.NET MVC illustrating the usage of the pattern:

public ActionResult ChangePassword(string currentPassword, string newPassword, string confirmPassword)
    if (ModelState.IsValid)
        MembershipUser currentUser = Provider.GetUser(User.Identity.Name, true /* userIsOnline */);

        // Attempt to change password
        bool changeSuccessful = currentUser.ChangePassword(currentPassword, newPassword);

        if (changeSuccessful)
           return RedirectToAction("ChangePasswordSuccess"); //PRG Pattern recommendation

    return View();