+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Virtual Path issue

Virtual Path issue

8 posts, 0 answered
  1. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    22 Mar 2012
    Link to this post
    Hi,

    I'm having the following problem with virtual paths:

    I have several custom controls that are referenced from my Sitefinity app. These custom controls have control view designers, referencing the embedded resources through a virtual path. When running the site from localhost the virtual path works fine and all the embedded resources are served fine (.acsx and .js files) and the site works fine. However when I move the site to a non-localhost domain these resource files are no longer served, instead I get 404 page not found errors for them. All other parts of the site work fine.

    What could be the cause of this? Both localhost and the domain version are running from my machine, so it isn't an issue between different machines.

    I can't pinpoint what the difference would be between the two sites to cause this problem?
  2. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    26 Mar 2012
    Link to this post
    Anyone? (sorry to bump my own post but this is holding up progress on a project)
  3. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    26 Mar 2012
    Link to this post
    Nick, I have some User Controls with designers as well. I have made the designer and the JS files as Embedded Resource. I then referenced them as ~/Controls/SomeControl.ascx, and after that, I went into the Administration -> Settings -> Advanced -> VirtualPathSettings -> Virtual paths and added another one as ~/Controls/*. That fixed my problem. I don't know if you are having the same issue though.
    Thanks, Andrei
  4. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    26 Mar 2012
    Link to this post
    Thanks Andrei, but that's how it's been done. The virtual paths are registered in code during application start and I've checked they show in the administration pages once the site is running.

    The confusing part is, it works perfectly on http://localhost but not on http://mytestdomain even though both of these are running from IIS on my local machine. 

    I don't know (and can't work out) if it is an issue with my application, or with some IIS settings. It's worth noting that this is happening on two separate projects now, so it isn't unique to this particular project.
  5. Travis
    Travis avatar
    86 posts
    Registered:
    15 Oct 2008
    31 May 2012
    Link to this post
    I'm having the EXACT same thing happening on my side, where the js files are set up as embeddable, the virtual path is set up, it works in local and doesn't work in production. Did you find a solution to this issue?
  6. Nick
    Nick avatar
    113 posts
    Registered:
    21 Oct 2008
    01 Jun 2012
    Link to this post
    Hi Travis,

    We got it resolved in the end through a discussion with the support team in a support ticket. Here are the pertinent points from discussion:

    Support: "Thank you for explaining the issue in such rich detail. I have been able to replicate the issue, however the approach to view the .js file directly from the string trough the virtual path is not valid. I don`t know why cassini(the web server integrated in visual studio) allows is. The problem seems to be related to something else in the module."

    So basically even though we could see the ,js files directly by URL, this is actually the WRONG behaviour - you shouldn't be able to. Something allowed it on the local machine, but it is not supposed to. So this led us to review our code again to see if we could find differences between a working and non-working project:

    Me: "(snip)... thanks for pointing me in the direction of the products sample, as I compared my .js files with the ones in that project and there were a few small differences. I made some adjustments and now have working designers (in both Cassini and in an IIS website) :)"

    So as you can see our issue was that our .js designer files were not right. When I compared them against the designers included in the Products sample project from the SDK I could see some differences. I can't remember what the difference was now, and I can't remember what example our original .js code was based on. Whatever it was it was wrong. Once we had redone our .js files based on the products examples, it was working fine.

    Hope that helps.
  7. Travis
    Travis avatar
    86 posts
    Registered:
    15 Oct 2008
    01 Jun 2012
    Link to this post
    Hi Nick,
    Thanks, that is a helpful tip. I will check my project and make sure everything is in its right place. I didn't realize that I wouldn't be able to navigate to my files with virtual paths, which isn't a problem, but it was how I was testing!

    Edit: Hmm... Chrome is reporting that the javascript files i'm embedding using the virtual paths are 404. I've added an alert to one of my javascript files and it fires in dev but does not fire in live. If the virtual path was working, then it would fire in live as well (the alert is not the result of a function call, it currently fires as soon as the script is included.) In my case, the virtual paths themselves are defined just as they are in the product sample.

    Edit 2: While my virtual paths are working for modules, they do not seem to work for a standalone project I've made. They work fine in development, but fail in the live environment. In the case of my project, it's not a module, its just a class library. I've done the following in my project. My project's file structure is in the attached screenshot, with the directory "WebsiteControls" being the topmost directory in the project

    I've also done the following:

    1. added, to the projects AssemblyInfo file, the following line:
    [assembly: WebResource("WebsiteControls.ControlDesigners.CallToActionDesigner.CallToActionDesignerScript.js", "application/x-javascript")]
    2. In my websites config files, for virtual paths (VirtualPathSettingsConfig.config), I have the following:
    <add resourceLocation="WebsiteControls" resolverName="EmbeddedResourceResolver" virtualPath="~/WebsiteControls/*" />
    3. In my designer, I'm referencing the virtual path in the following way:
    private string _scriptReference = "~/WebsiteControls/WebsiteControls.ControlDesigners.CallToActionDesigner.CallToActionDesignerScript.js";
    4. That variable, _scriptReference, is used in the following way:
    public override IEnumerable<ScriptReference> GetScriptReferences()
            {
                // get script collection
                var scripts = base.GetScriptReferences() as List<ScriptReference>;
                if (scripts == null) return base.GetScriptReferences();

                scripts.Add(new ScriptReference(_scriptReference));

                return scripts.ToArray();
            }
  8. Basem
    Basem avatar
    131 posts
    Registered:
    22 Dec 2010
    16 Feb 2013
    Link to this post

    The generated code by Thunder is wrong if you plan on putting it into your own class library. The trick is to get the resource name without anything to do with Virtual Paths:

    public static readonly string ScriptReference = "MyClass.Resources.MyFile.js";
    ...
    public override IEnumerable<ScriptReference> GetScriptReferences()
    {
       var assemblyName = this.GetType().Assembly.FullName;
       scripts.Add(new ScriptReference(this.ScriptReference, assemblyName));
       ...
    }

    Not sure why, but you don't even have to register them in AssemblyInfo.cs.

8 posts, 0 answered