0

I added a new Web Site and onLoad Event of the Page I try to Load Xml

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(@"‪D:\languages\Lang-Ru.xml"); //ERROR
    }
}

When I start the site, there is an error:

An exception of type 'System.NotSupportedException' occurred in mscorlib.dll but was not handled in user code

Additional information: The given path's format is not supported

StackTrace:

в System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath) в System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath) в System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList) в System.IO.Path.GetFullPath(String path) в System.Xml.XmlResolver.ResolveUri(Uri baseUri, String relativeUri)
в System.Xml.XmlTextReaderImpl..ctor(String url, XmlNameTable nt) в System.Xml.XmlDocument.Load(String filename) в _Default.Page_Load(Object sender, EventArgs e) в d:\sample\Default.aspx.cs:строка 14 в System.Web.UI.Control.LoadRecursive() в System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Can anybody help me? Maybe there is some illegal settings in IIS.

melnynet
  • 69
  • 1
  • 8
  • This might help: http://stackoverflow.com/questions/8996157/how-to-enable-file-system-access-to-web-service – Matt Aug 04 '14 at 13:08

1 Answers1

0

Web sites can't access the local drive. They can only access the area where the HTML is stored or a location below that. This of the security risk if they could.

You want to add the xml file to the content area of the website and then use a relative path to that location.

There are a number of ways to "get around" the above limitation -- but there are few good reasons to do so. If you want to access XML content, the best way to do that is have the IIs software manage the rights and access to the file. You will be much less likely to expose your self to security vulnerabilities.

Hogan
  • 69,564
  • 10
  • 76
  • 117
  • Or the user should have the permission of that folder explicitly [Link](http://stackoverflow.com/questions/5437723/iis-apppoolidentity-and-file-system-write-access-permissions). – शेखर Aug 04 '14 at 13:09
  • If I use @"‪file:///D:\languages\Lang-Ru.xml" it doesn't throw an Exception. But my friends use the first sample of Path and it's ok – melnynet Aug 04 '14 at 13:10
  • @user2777827 - see additional comment above – Hogan Aug 04 '14 at 13:15