.NET ROUTING和ajax sys未定义

时间:2022-01-26 07:07:03

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

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

I'm using .net 3.5 w/ c#

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

any help would be much appreciated.

任何帮助将非常感激。

1 个解决方案

#1


0  

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

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

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

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

在这种情况下,此路由评估语言环境键和页面键的正则表达式,然后您需要评估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;
}

I hope that this will help you.

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

#1


0  

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

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

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

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

在这种情况下,此路由评估语言环境键和页面键的正则表达式,然后您需要评估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;
}

I hope that this will help you.

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