简体   繁体   English

ASP页面具有URL映射时未加载ASP.NET Javascript

[英]ASP.NET Javascript Not being loaded when ASP Page has URL Mapping

I'm trying to retrieve the ID of an employee and show them in my details page by retrieving the Employee ID from the URL using Page Mapping in ASP.NET: 我试图通过使用ASP.NET中的页面映射从URL检索员工ID来检索员工ID并将其显示在我的详细信息页面中:

RouteTable.Routes.MapPageRoute("", "employee/{id}", "~/details.aspx");

Such that the URL will be: 这样的URL将是:

www.myexamplewebsite.com/employee/7937822353 www.myexamplewebsite.com/employee/7937822353

The problem is, the Javascript files don't get loaded and the console is full of my javascript errors. 问题是,无法加载Javascript文件,并且控制台中充满了我的JavaScript错误。 I get a 404 error in my JS scrips as well. 我的JS脚本也收到404错误。 The page can't find any JS file when mapped. 映射后,该页面找不到任何JS文件。 Why is this happening when I map the URL? 为什么在映射URL时会发生这种情况? This does not happen if the URL is www.myexamplewebsite.com/7937822353. 如果URL为www.myexamplewebsite.com/7937822353,则不会发生这种情况。

What am I doing wrong? 我究竟做错了什么?

EDIT: 编辑:

This is how my JS files are referenced: 这是引用我的JS文件的方式:

 <script src="js/chatbar/rightside.js"> </script>

The script is relative, and it's from the perspective of the client side URL. 该脚本是相对的,并且是从客户端URL的角度来看的。 So when you change the page route to have the page appear to be served from a /employee subdirectory, the correct relative path to your scripts changes. 因此,当您更改页面路由以使该页面看起来可以从/employee子目录提供时,脚本的正确相对路径也会更改。 So it's looking for the scripts at /employee/js/charbar/rightside.js . 因此,它正在/employee/js/charbar/rightside.js寻找脚本。 You could change those relative paths (to something like ../js/chartbar/rightside.js ), but you might run into a problem later if you change the routing again. 您可以更改这些相对路径(更改为../js/chartbar/rightside.js类的../js/chartbar/rightside.js ),但是如果再次更改路由,以后可能会遇到问题。

So instead, it's best to make the reference application root relative . 因此,最好将参考应用程序设为root相对

<script src='<%= ResolveClientUrl("~/js/chatbar/rightside.js")%>'></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM