Building XML based routing system using XRouter

Routes are part of an application and they are defined through code in the Application_Start event. Routes not changes frequently but whenever they requires a change we need to modify the code. In applications where we need frequent changes in routing configuration, defining routes in code is not a flexible option and a better idea would be to place them in xml files or database.

I've created a simple API named XRouter that helps you to define routes in xml files. XRouter helps you to map, ignore and redirect requests quite easily. It also helps you to manage areas in a flexible way. The main advantage is whenever you change the routes, the routing table is automatically updated and you don't need to restart the application.

Continue Reading

Understanding Routing

One of the important feature of ASP.NET MVC is Routing. The Routing infrastructure helps us to map the incoming requests to controllers and actions. The routing module ships with a separate assembly System.Web.Routing and that helps us to use the routing infrastructure outside ASP.NET MVC applications, like in Webforms.

In this article we are going to see about the important details of routing infrastructure. First we start from basics and slowly move to the advanced concepts and at-last we see how we can simplify creating routes by using our own extension methods. For people who are already familiar with the basic things they can jump to the last section where we discuss about creating cool extension methods and that's fun.

Continue Reading

Preventing access to folders using RouteExistingFiles property

When a user request for a static resource like an image, video etc. that is located in a particular folder the ASP.NET happily serves that resource to the user unless we have set some restrictions. Sometimes we need to protect these folders from delivering these resources to users other than the owner. In simple cases we can prevent this through web.config settings but in complex cases like it would be nice if we could control the accessibility through an action/filter and for that we have to direct those requests through MVC pipeline and there comes the RouteExistingFiles property. By setting this property to true we can say MVC to handle those requests instead of giving that responsibility to IIS.

In this article we will see how we can utilize the RouteExistingFiles property with an authorization filter to prevent users from accessing unauthorized resources.

Continue Reading

Creating custom route constraints in ASP.NET MVC

In ASP.NET MVC the Routing Module is the URL routing engine that directs the incoming requests to controller actions. There are cases where we need to impose constraints over the incoming requests that are mapped routes. These constraints are used to avoid from directing invalid requests to the controller actions.

In this article we are going to see how to create a simple custom route constraint and supply it to a mapped route.

Continue Reading

Routing Service and Content Based Routing

In Service Oriented Applications there are many cases we need an intermediate software between clients and services that bypasses the communication between them. The intermediate software is typically called as a router. Some of the well-known examples where we need a router are protocol mapping (ex. the service is exposed to tcp while the clients expects http), load-balancing (ex. distributing messages to services running in different servers in a round-robin fashion), content-based routing (routing messages to different services based upon the message content) etc.

WCF 4.0 ships with a new service called Routing Service that makes developers life so easy by separating out the routing logic from the clients and services. The nice thing about the Routing Service is it is so easily pluggable and configurable. This Routing Service is available under the new assembly System.ServiceModel.Routing.

In this article I’m going to describe about how we can achieve content-based routing using the WCF Routing Service.

Continue Reading