.NET ROUTING和ajax sys未定义

时间:2009-08-25 17:05:12

标签: ajax routing

每当我的web.CONFIG中包含.NET路由时,我都会收到一个sys undefined错误,该错误会阻止加载ajax。

我正在使用.net 3.5 w / c#

任何帮助都会非常感激。

1 个答案:

答案 0 :(得分:0)

您需要在路线上使用Route Constrains,这意味着您必须在属性Contraints中的Route实例中添加RouteValueDictionary

以下示例显示如何使用虚拟文件夹指示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" }
     }
});

在这种情况下,此路由评估语言环境键和页面键的正则表达式,然后您需要评估IRouteHandler类中的所有键

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;
}

我希望这会对你有所帮助。