save xml file

farshad

Well-known member
Joined
May 1, 2003
Messages
109
Location
London
I am still unable to save data into my xml file.
The error is:
----------------------------------------
Access to the path "c:\inetpub\wwwroot\Farshad\ASP.NET\DSL\ctcUsers.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:\inetpub\wwwroot\Farshad\ASP.NET\DSL\ctcUsers.xml" is denied.

The ASP.NET process is not authorized to access the requested resource. For security reasons the default ASP.NET process identity is {machinename}\ASPNET, which has limited privileges. Consider granting access rights to the resource to the ASP.NET process identity.

To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the "{machinename}\ASPNET" user. Highlight the ASP.NET account, and check the Write box in the Allow column.
----------------------------------------

This is the code that I am using to save into the xml file.
Please remember that this procedure works fine if I use a vb.net application but it gives the above error when in ASP.NET

p.s. The ctcUsers.xml is NOT readonly in explorer

Private Sub SaveDataToXML()
Dim strPath As String = Server.MapPath(Request.ApplicationPath)
Dim doc As XmlDocument = New XmlDocument()

doc.Load(strPath & "\ctcUsers.xml")
Dim rootNode As XmlElement = doc.DocumentElement

Dim NewUser As XmlElement = doc.CreateElement("User")

Dim NewFirstName As XmlElement = doc.CreateElement("firstname")
NewFirstName.InnerText = txtFirstName.Text
NewUser.AppendChild(NewFirstName)

Dim NewSurname As XmlElement = doc.CreateElement("surname")
NewSurname.InnerText = txtSurname.Text
NewUser.AppendChild(NewSurname)

Dim NewAge As XmlElement = doc.CreateElement("age")
NewAge.InnerText = txtAge.Text
NewUser.AppendChild(NewAge)

Dim NewPhone As XmlElement = doc.CreateElement("phone")
NewPhone.InnerText = txtPhone.Text
NewUser.AppendChild(NewPhone)

Dim NewEmail As XmlElement = doc.CreateElement("email")
NewEmail.InnerText = txtEmail.Text
NewUser.AppendChild(NewEmail)

rootNode.AppendChild(NewUser)

Here is when the error occurs.......................
doc.Save(strPath & "\ctcUsers.xml")
.....................................................

End Sub
 
It says to do the following:
To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the "{machinename}\ASPNET" user. Highlight the ASP.NET account, and check the Write box in the Allow column.

BUT, when I right click on the .xml file in explorer it only shows the general tab. I dont know where else to check to set the permissions, etc.
Thanks
 
Your IIS is probably managing the security.
In XP, Control Panel/Administrative Tools/Internet Information Services/...right click on your website and select properties.
"Directory Security" allows for Annonymous Access or Authenticated Access.

Jon
 
I tried it.

I put a check at anonymous access, and changed the user to LTZ/ASPNET (LTZ is my computer). I could already read the xml file, i just can;t write to it.

Reading it works fine, but alas, writing gives

System.UnauthorizedAccessException: Access to the path "C:\Inetpub\wwwroot\EetlijstWebService\outlook.xml" is denied.


Not it I;m afraid, what am I missing. Why can the webservice, accessed by a client that comes in over the internet ,not write to a file?
 
Have you tried "Web Sharing" in the properties of the folder containing the xml?
Select "Share this folder" and then in "Access Permisions" check write as well as read.

Jon
 
The final step of installing .net is as follows:

To configure IIS after running setup on Windows .NET Servers
On the Start menu, choose All Programs.
Choose Administrative Tools and then choose Internet Information Services.
Right-click your machine name in left pane and choose Security.
Click Next on the first screen of the IIS Security Lockdown Wizard.
Verify that HTTP: is set to Automatic and click Next.
In the Request Handlers list, check ASP.NET and each instance of n:\WINDOWS\Microsoft.NET\Framework\<version number>\aspnet_isapi.dll.
Click Next.
Click Finish to complete the wizard.

I can not do that, it applies to NT, but not XP. How can this be solved?

tx Vincent
 
Back
Top