我正在尝试在DNN模块中嵌入javascript文件,脚本标记已创建但内容为404错误。
我项目的命名空间是“Carroussel”我文件的位置是“js / jquery-carouFredSel-6.2.1.js”
我已将以下代码添加到AssemblyInfo.cs
[assembly: WebResource("Carroussel.js.jquery-carouFredSel-6.2.1.js", "application/javascript", PerformSubstitution = true)]
以下是模块的OnInit:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Page.ClientScript.RegisterClientScriptResource(GetType(), "Carroussel.js.jquery-carouFredSel-6.2.1.js");
}
脚本标签是在我的html中创建的:
<script src="/WebResource.axd?d=gnpD_kHZKrDN3DKUCn2faE-x6tdus2cDJ1HjymfAToCQgqX2ggJno51OH2VqPx8ArZPoUm5RuWxhg8uAOTZaysKJE7jz3kpB6gHWbD25o2plphslAJao3Rs5ybJz_M9vLB1NmgPujgOBCt3pDGs9aY_lTy04oPXMqX6dyz0AHhjrbZlKl8muO0ZRGnAiWwdicmeAlg2&t=635349640675857733" type="text/javascript"></script>
但是只要我查看源代码,我就会:
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /WebResource.axd
有关改变什么以使其有效的任何想法?
答案 0 :(得分:1)
我建议您不要嵌入它,但让DNN处理资源的注册/加载。如果您在DNN中禁用了CDF,那么这样做将允许您轻松查看对JS的引用,并屏蔽引用并使内容在DNN中启用CDF时缩小。
以下是如何在DNN中引用客户端资源管理器。
override protected void OnInit(EventArgs e)
{
DotNetNuke.Framework.jQuery.RequestUIRegistration();
ClientResourceManager.RegisterScript(Parent.Page, "~/Resources/Shared/scripts/knockout.js");
ClientResourceManager.RegisterScript(Parent.Page, "~/desktopmodules/DnnChat/scripts/moment.min.js");
ClientResourceManager.RegisterScript(Parent.Page, "~/desktopmodules/DnnChat/scripts/DnnChat.js",150);
base.OnInit(e);
}
从https://github.com/ChrisHammond/dnnCHAT/blob/master/View.ascx.cs拉出