Note that there are some explanatory texts on larger screens.

plurals
  1. POGoDaddy won't let XmlUrlResolver run
    primarykey
    data
    text
    <p>I am trying to write a page to host on and the code keeps throwing an exception. I believe that the problem is that the permissions on the server will not let the subclass of XmlUrlResolver get instantiated, but I'd love some help with this please...</p> <p>This code does work on my local dev box, and if I use File.ReadAllText(HostingEnvironment.MapPath("~/xml/home.xml")) it does work, so I am fairly certain it's not IO permissions....</p> <p>Exception:</p> <pre><code> Security Exception Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. Exception Details: System.Security.SecurityException: Request failed. Source Error: Line 33: t.Load(reader, null, new XsltUrlResolver()); Line 34: sb = new StringBuilder(File.ReadAllText(HostingEnvironment.MapPath("~/xslt/url-encode.xslt"))); Line 35: } Line 36: &lt;/script&gt; Line 37: </code></pre> <p>Code (this is a simple page I'm using to try to narrow down the problem only):</p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" EnableViewState="false" Inherits="System.Web.UI.Page" %&gt; &lt;%@ Import Namespace="Web" %&gt; &lt;%@ Import Namespace="System.Xml" %&gt; &lt;%@ Import Namespace="System.Web.Hosting" %&gt; &lt;%@ Import Namespace="System.IO" %&gt; &lt;%@ Import Namespace="System.Xml.Xsl" %&gt; &lt;%@ Import Namespace="System.Text" %&gt; &lt;%@ Import Namespace="System.Web" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;script runat="server"&gt; public StringBuilder sb = new StringBuilder(); public class XsltUrlResolver : XmlUrlResolver { public override Uri ResolveUri(Uri baseUri, string relativeUri) { if (baseUri != null) return base.ResolveUri(baseUri, relativeUri); else return base.ResolveUri(baseUri, HostingEnvironment.MapPath(relativeUri)); } } protected void Page_Load(object sender, EventArgs e) { // create the readers for the xml and xsl XmlReader reader = XmlReader.Create(new StringReader(File.ReadAllText(HostingEnvironment.MapPath("~/xslt/home.xslt")))); XmlReader input = XmlReader.Create(new StringReader(File.ReadAllText(HostingEnvironment.MapPath("~/xml/home.xml")))); // create the xsl transformer XslCompiledTransform t = new XslCompiledTransform(true); t.Load(reader, null, new XsltUrlResolver()); sb = new StringBuilder(File.ReadAllText(HostingEnvironment.MapPath("~/xslt/url-encode.xslt"))); } &lt;/script&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head id="Head1" runat="server"&gt; &lt;title&gt;Untitled Page&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;%= sb.ToString() %&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload