Getting an XSLT file to load when the site is hosted on a network share

November 25, 2013 at 10:53 AMMadestro

So I was working on a website the other day and had a bunch of XSLT templates that were used to produce HTML for e-mails.

Well, no e-mails were coming through. Further investigation revealed the issue to be that the XslCompiledTransform.Load() method call was failing with a System.IO.FileNotFound error.

When I looked at the  actual physical path for the file that resulted from the call to Server.MapPath(), I realized that the site was actually being hosted on a network share (e.g. \\someserver\sites\x\content\web\xsltfile.xslt)

 The issue in this case turned out to be Network Access permissions.

 You see, the issue with this setup is that the application pool runs under a particular identity (e.g. NetworkService). Because the file we are trying to read actually seats on a NETWORK share, the account the pool is running in does not have permissions to read the file so we need to authenticate. Unfortunately the error thrown is misleading since the path is correct. It's just that it cannot reach the file due to permissions.

There are ways in which you can perform authentication but that involves internal knowledge of the network share and more times than not it is less than ideal since most people use a hosting provider.

And then, after being transferred four times to someone else by RackSpace support, it hit me!...

If you keep your XSLT files within the public realm of your website, you can have it served to you by the web server.

In other words, simply consume it as a web resource. The XslCompiledTransform.Load() method supports a URI as a parameter (or string representing one):

string sampleAddress = "";
XslCompiledTransform transform = new XslCompiledTransform();


And that's all there is to it. Laughing

Posted in: ASP.NET MVC