0

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.

ErnieStings
  • 6,333
  • 19
  • 47
  • 54
  • There is already a very good answer by [Haacked](http://stackoverflow.com/users/598/haacked) [here](http://stackoverflow.com/questions/273447/how-to-ignore-route-in-asp-net-forms-url-routing#answer-276036). Solved my problem at least. – Shagglez Sep 02 '10 at 15:13

1 Answers1

0

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.

Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202