tags:

views:

28

answers:

2

Whenever .NET routing is included in my web.CONFIG i get a sys undefined error which prevents ajax from being loaded.

I'm using .net 3.5 w/ c#

any help would be much appreciated.

A: 

You need to use Route Constrains on your routes, it means that you must add a RouteValueDictionary in Route instance in property Contraints

The following example shows how use a virtual folder for indicate the UICulture.

e.g.:

RouteTable.Routes.Add(new Route("{locale}/{page}", new CultureRouter())
{
    Constraints = new RouteValueDictionary() { 
        { "locale", "[a-z]{2}-[a-z]{2}" } ,
        { "page", "([a-z0-9]*).aspx" }
    }
});
RouteTable.Routes.Add(new Route("{folder}/{page}", new CultureRouter())
{
    Constraints = new RouteValueDictionary() { 
        { "page", "([a-z0-9]*).aspx" }
    }
});
RouteTable.Routes.Add(new Route("{locale}/{folder}/{page}", new CultureRouter())
{
     Constraints = new RouteValueDictionary() { 
          { "locale", "[a-z]{2}-[a-z]{2}" } ,
          { "page", "([a-z0-9]*).aspx" }
     }
});

In this case, this route evaluate a regular expression for locale key, and page key, and then you need to evaluate all keys in your IRouteHandler class

e.g:

public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
    StringBuilder virtualPath = new StringBuilder("~/Pages/");

    if (requestContext.RouteData.Values.ContainsKey("locale"))
    {
        Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(requestContext.RouteData.Values["locale"].ToString());
    }

    if (requestContext.RouteData.Values.ContainsKey("folder"))
    {
        virtualPath.AppendFormat("{0}/", requestContext.RouteData.Values["folder"].ToString());
    }

    if (requestContext.RouteData.Values.ContainsKey("page"))
    {
        virtualPath.Append(requestContext.RouteData.Values["page"].ToString());
    }

    IHttpHandler pageHandler = BuildManager.CreateInstanceFromVirtualPath(virtualPath.ToString(), typeof(Page)) as IHttpHandler;

    return pageHandler;
}

I hope that this will help you ;)

DarkFrost

Darkfrost
A: 

There is already a very good answer by Haacked here. Solved my problem at least.

Shagglez