Virtual Path issue
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?
Anyone? (sorry to bump my own post but this is holding up progress on a project)
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
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?
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) :)"
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();
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.