Question

I'm trying to embed a javascript file in a DNN module, the script tag is created but the content is a 404 error.

The namespace of my project is "Carroussel" the location of my file is "js/jquery-carouFredSel-6.2.1.js"

I've added the following code to AssemblyInfo.cs

[assembly: WebResource("Carroussel.js.jquery-carouFredSel-6.2.1.js", "application/javascript", PerformSubstitution = true)]

And the following to the OnInit of the module:

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);

    Page.ClientScript.RegisterClientScriptResource(GetType(), "Carroussel.js.jquery-carouFredSel-6.2.1.js");
}

The scripttag is created in my html:

<script src="/WebResource.axd?d=gnpD_kHZKrDN3DKUCn2faE-x6tdus2cDJ1HjymfAToCQgqX2ggJno51OH2VqPx8ArZPoUm5RuWxhg8uAOTZaysKJE7jz3kpB6gHWbD25o2plphslAJao3Rs5ybJz_M9vLB1NmgPujgOBCt3pDGs9aY_lTy04oPXMqX6dyz0AHhjrbZlKl8muO0ZRGnAiWwdicmeAlg2&amp;t=635349640675857733" type="text/javascript"></script>

But as soon as I view the source i get:

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

Any ideas on what to change to make this working?

Was it helpful?

Solution

I would recommend that you not embed it, but let DNN handle the registration/loading of the resource. Doing so will allow you to easily see references to the JS if you have CDF disabled in DNN, and mask the references and have the content minified with CDF enabled in DNN.

Here is how to reference the client resource manager in 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);
}

pulled from https://github.com/ChrisHammond/dnnCHAT/blob/master/View.ascx.cs

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top