Access Denied error [modified]
-
I am relatively new to ASP.NET and have just uploaded my first page. I have a "Save" function that writes information from a control to an XML file. Whenever I try to run this function I get this error from ASP.NET: Server Error in '/' Application. -------------------------------------------------------------------------------- Access to the path 'c:\windows\system32\inetsrv\favorites.xml' is denied. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.UnauthorizedAccessException: Access to the path 'c:\windows\system32\inetsrv\favorites.xml' is denied. ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user. To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access. -------------------------------------------------------------------------------------- I'm not sure how to change the access rights because I am using a web hosting service. It works fine on my local machine. What should I do from here?
-
I am relatively new to ASP.NET and have just uploaded my first page. I have a "Save" function that writes information from a control to an XML file. Whenever I try to run this function I get this error from ASP.NET: Server Error in '/' Application. -------------------------------------------------------------------------------- Access to the path 'c:\windows\system32\inetsrv\favorites.xml' is denied. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.UnauthorizedAccessException: Access to the path 'c:\windows\system32\inetsrv\favorites.xml' is denied. ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user. To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access. -------------------------------------------------------------------------------------- I'm not sure how to change the access rights because I am using a web hosting service. It works fine on my local machine. What should I do from here?
-
I am relatively new to ASP.NET and have just uploaded my first page. I have a "Save" function that writes information from a control to an XML file. Whenever I try to run this function I get this error from ASP.NET: Server Error in '/' Application. -------------------------------------------------------------------------------- Access to the path 'c:\windows\system32\inetsrv\favorites.xml' is denied. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.UnauthorizedAccessException: Access to the path 'c:\windows\system32\inetsrv\favorites.xml' is denied. ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user. To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access. -------------------------------------------------------------------------------------- I'm not sure how to change the access rights because I am using a web hosting service. It works fine on my local machine. What should I do from here?
HI, Can you write the code here that you are using. Thanks, Sushant Duggal.
-
HI, Can you write the code here that you are using. Thanks, Sushant Duggal.
Here is the code that I am using. I am referencing the file in the last sub-routine "Save_Click".
Sub SaveNodes(ByVal nodesCollection As TreeNodeCollection, ByVal textWriter As System.Xml.XmlTextWriter)
Dim link_node As TreeNode
For Each link_node In nodesCollection
If link_node.ChildNodes.Count Then
textWriter.WriteStartElement("Folder")
textWriter.WriteAttributeString("Name", link_node.Text)
textWriter.WriteRaw(vbCrLf)
Else
textWriter.WriteStartElement("Link")
textWriter.WriteAttributeString("Name", link_node.Text)
textWriter.WriteAttributeString("Location", link_node.NavigateUrl)
End IfIf link\_node.ChildNodes.Count > 0 Then SaveNodes(link\_node.ChildNodes, textWriter) End If textWriter.WriteEndElement() textWriter.WriteRaw(vbCrLf) Next
End Sub
Sub SaveTreeViewData(ByVal treeView As TreeView, ByVal path As String)
'Create a serializer and file to save TreeViewData
Dim TextWriter As New System.Xml.XmlTextWriter(path, System.Text.Encoding.UTF8)TextWriter.WriteStartDocument() TextWriter.WriteRaw(vbCrLf) SaveNodes(treeView.Nodes, TextWriter) TextWriter.Close()
End Sub
Protected Sub Save_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Save.Click
SaveTreeViewData(Link_Tree, "favorites.xml")
End Sub