错误 404:从脚本文件夹渲染jquery-1.4.1.min.js时

huangapple go评论75阅读模式
英文:

Error 404: when rendering jquery-1.4.1.min.js from Script folder

问题

  • 网站:https://abc.xyz.com/emrsso

  • IIS 设置:站点 > SHC > EMRSSO

  • 虚拟路径:/EMRSSO

  • 默认文档:SSOLogin.aspx

  • 物理路径:D:\Renesan\SHCTest\EMRSSO

还有一个位于 EMRSSO 下的 Scripts 文件夹,例如 D:\Renesan\SHCTest\EMRSSO\Scripts。

然后在 Scripts 文件夹下有 jquery-3.4.1.min.js,例如 D:\Renesan\SHCTest\EMRSSO\Scripts\jquery-3.4.1.min.js。

当我访问 https://abc.xyz.com/emrsso 时,出现 404 错误或者 jquery-3.4.1.min.js 无法加载,在 Chrome 开发工具中调试时,路径显示为 'https://abc.xyz.com/Scripts/jquery-3.4.1.min.js' 而不是 'https://abc.xyz.com/emrsso/Scripts/jquery-3.4.1.min.js'。

当我访问 https://abc.xyz.com/emrsso/SSOLogin.aspx 时,jquery-3.4.1.min.js 能够成功加载,在 Chrome 开发工具中调试时,路径显示为 'https://abc.xyz.com/emrsso/Scripts/jquery-3.4.1.min.js',这是正确的。

当我通过 Visual Studio 调试我的应用时,jquery-3.4.1.min.js 能够成功加载并正常工作。

SSOLogin.aspx 中的 ASPX 代码:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="SSOLogin.aspx.vb" Inherits="EHR_Web.SSOLogin" %>

<script src="https://global.oktacdn.com/okta-signin-widget/5.2.0/js/okta-sign-in.min.js" type="text/javascript"></script>
<link href="https://global.oktacdn.com/okta-signin-widget/5.2.0/css/okta-sign-in.min.css" type="text/css" rel="stylesheet" />
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

我已经查看了其他问题:
https://stackoverflow.com/questions/37556913/why-iis-doesnt-handle-relative-path-the-same-way-iis-express-does

然而,我没有找到解决方法。这里可能出了什么问题?

英文:
  • Website: https://abc.xyz.com/emrsso

  • IIS Setup: Site > SHC > EMRSSO

  • Virtual Path: /EMRSSO

  • Default Document: SSOLogin.aspx

  • Physical path: D:\Renesan\SHCTest\EMRSSO

And also there is Scripts folder under EMRSSO e.g. D:\Renesan\SHCTest\EMRSSO\Scripts.

Then there is jquery-3.4.1.min.js under Scripts folder e.g. D:\Renesan\SHCTest\EMRSSO\Scripts\jquery-3.4.1.min.js

when I visit https://abc.xyz.com/emrsso, It is 404 error or jquery-3.4.1.min.js, on debugging I found in chrome dev tool path is showing as
'https://abc.xyz.com/Scripts/jquery-3.4.1.min.js' instead of 'https://abc.xyz.com/emrsso/Scripts/jquery-3.4.1.min.js'

when I visit https://abc.xyz.com/emrsso/SSOLogin.aspx, jquery-3.4.1.min.js is rendering successfully and on debugging in chrome dev tool path is showing as
'https://abc.xyz.com/emrsso/Scripts/jquery-3.4.1.min.js' which is fine.

When I debug my application through Visual Studio jquery-3.4.1.min.js is rendering successfully and working fine.

ASPX Code for jquery-3.4.1.min.js:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="SSOLogin.aspx.vb" Inherits="EHR_Web.SSOLogin" %>

<script src="https://global.oktacdn.com/okta-signin-widget/5.2.0/js/okta-sign-in.min.js" type="text/javascript"></script>
<link href="https://global.oktacdn.com/okta-signin-widget/5.2.0/css/okta-sign-in.min.css" type="text/css" rel="stylesheet" />
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

I have gone through other question:
https://stackoverflow.com/questions/37556913/why-iis-doesnt-handle-relative-path-the-same-way-iis-express-does

However I did not find any resolution. what can be wrong here?

答案1

得分: 1

尝试解析您的URL,这将使路径保持一致,无论页面/控件位于哪个文件夹中。

<script src="<%=ResolveUrl("~/Scripts/jquery-1.4.1.min.js")%>" type="text/javascript"></script>

有关详细信息,请访问:https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.control.resolveurl?view=netframework-4.8.1

英文:

Try resolving your URL, this keeps the path consistent regardless of which folder a page/control is in.

&lt;script src=&quot;&lt;%=ResolveUrl(&quot;~/Scripts/jquery-1.4.1.min.js&quot;)%&gt;&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;

https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.control.resolveurl?view=netframework-4.8.1

huangapple
  • 本文由 发表于 2023年5月10日 16:39:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76216458.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定