ASP.NET 4.0 WebForms的路由的Javascript没有作品 [英] ASP.NET 4.0 WebForms Routing Javascript not works

查看:108
本文介绍了ASP.NET 4.0 WebForms的路由的Javascript没有作品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用ASP.NET 4.0 WebForms的路由。这里是我的RegisterRoutes功能:

 无效的RegisterRoutes(RouteCollection路线)
    {
        routes.Ignore({}资源个.axd / {*} PATHINFO);
        routes.MapPageRoute(GoodInfo,产品目录/好/ {}好,〜/ GoodInfo.aspx);
        routes.MapPageRoute(GoodGroup,目录/组/ {}组,〜/ Default.aspx的);
    }

对于像网页 /目录/组/ {组} 一切正常。但也有与网页的问题目录/好/ {好}

首先奇怪的事情:当我打开这个网页它调用两次。所以我看到什么样的价值来为 Page.RouteData.Values​​ [好] 。在第一时间 Page.RouteData.Values​​ [好] 具有正确的价值(我goodId),但我第二次拿到了字符串值WebResource.axd的<! / p>

所以,我highslide JavaScript并没有在页面上工作。当我highslide图像上单击执行JavaScript的页面重载而不是

我添加这一行 routes.Ignore({}资源个.axd / {*} PATHINFO); 但它并没有帮助我。任何想法?


解决方案

我已经解决了我的问题!该解决方案由两部分组成。
首先,我改变了我的剧本的定义从

 &LT;脚本类型=文/ JavaScript的SRC =../脚本/ something.js&GT;&LT; / SCRIPT&GT;

 &LT;脚本类型=文/ JavaScript的SRC =/../脚本/ something.js&GT;&LT; / SCRIPT&GT;

MilkyWayJoe FOT该解决方案。

其次,我添加忽略路由

  routes.Ignore(目录/好/ {}资源个.axd / {*} PATHINFO);

而不是:

  routes.Ignore({}资源个.axd / {*} PATHINFO);

所以,我的网络资源,对像 http://mysite.com/catalog/good/41

页没有更多的途径

我也有类似页面 http://mysite.com/catalog/good/41/event/seq/1 上的脚本事件。为了赶上我添加到路由所有的参数规则,本

  routes.Ignore(目录/好/ {好} / {*} QUERY1);
   routes.Ignore(目录/好/ {好} / {QUERY1} / {*} QUERY2);
   routes.Ignore(目录/好/ {好} / {QUERY1} / {QUERY2} / {*} QUERY3);
   routes.Ignore(目录/好/ {好} / {QUERY1} / {QUERY2} / {QUERY3} / {*} query4);

和不要忘记,你的忽略的声明必须在的MapPageRoute 的声明放在:

  routes.Ignore(目录/好/ {}资源个.axd / {*} PATHINFO);
routes.MapPageRoute(GoodInfo,产品目录/好/ {}好,〜/ GoodInfo.aspx);`输入code here`

I'm try to use ASP.NET 4.0 WebForms Routing. Here is my RegisterRoutes function:

 void RegisterRoutes(RouteCollection routes)
    {
        routes.Ignore("{resource}.axd/{*pathInfo}"); 
        routes.MapPageRoute("GoodInfo", "catalog/good/{good}", "~/GoodInfo.aspx");
        routes.MapPageRoute("GoodGroup", "catalog/group/{group}", "~/default.aspx");
    }

For pages like /catalog/group/{group} everything is ok. But there are problems with pages catalog/good/{good}.

First strange thing: when I open this page it calls twice. So I see what value comes for Page.RouteData.Values["good"]. First time in Page.RouteData.Values["good"] has the right value (my goodId) but the second time I got the string value "WebResource.axd"!

So my highslide JavaScript does not work on the page. And when I click on highslide image the page reloads instead of executing the JavaScript.

I added this line routes.Ignore("{resource}.axd/{*pathInfo}"); but it didn't helped me. Any ideas?

解决方案

I have solved my problem! The solution consists of 2 parts. Firstly I changed my scripts definition from

<script type="text/javascript" src="../scripts/something.js"></script>

to

<script type="text/javascript" src="/../scripts/something.js"></script>

Thanks MilkyWayJoe fot that solution.

Secondly I added Ignore Routing

routes.Ignore("catalog/good/{resource}.axd/{*pathInfo}");

instead of:

routes.Ignore("{resource}.axd/{*pathInfo}");

So my web resources have no more routes on pages like http://mysite.com/catalog/good/41

Also I have script events on the page like http://mysite.com/catalog/good/41/event/seq/1. To catch all parameters I add to my route rules this

   routes.Ignore("catalog/good/{good}/{*query1}");
   routes.Ignore("catalog/good/{good}/{query1}/{*query2}");
   routes.Ignore("catalog/good/{good}/{query1}/{query2}/{*query3}");
   routes.Ignore("catalog/good/{good}/{query1}/{query2}/{query3}/{*query4}");

And don't forget that your Ignore declarations must be placed before MapPageRoute declarations:

routes.Ignore("catalog/good/{resource}.axd/{*pathInfo}");
routes.MapPageRoute("GoodInfo", "catalog/good/{good}", "~/GoodInfo.aspx");`enter code here`

这篇关于ASP.NET 4.0 WebForms的路由的Javascript没有作品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆