Solved

Access to the path is denied

Posted on 2006-10-24
6
1,203 Views
Last Modified: 2008-01-09
I have the following code:

Try
            webReqGateway = WebRequest.Create("http://drv.sax.softvoyage.com/cgi-bin/gateway_dest.cgi")
            webReqHotel = WebRequest.Create("http://drv.sax.softvoyage.com/cgi-bin/dest_hotels.cgi")
            webResGateway = webReqGateway.GetResponse
            webResHotel = webReqHotel.GetResponse
            strmGateway = New StreamReader(webResGateway.GetResponseStream)
            xmlGateway = New StreamWriter(Server.MapPath("//XML/Gateway.xml"), False)
            xmlHotel = New StreamWriter(Server.MapPath("//XML/Hotel.xml"), False)
            'Console.WriteLine(strmGateway.ReadLine.ToString)
            xmlGateway.WriteLine(strmGateway.ReadToEnd)
            strmHotel = New StreamReader(webResHotel.GetResponseStream)
            xmlHotel.WriteLine(strmHotel.ReadToEnd)
            xmlGateway.Close()
            xmlHotel.Close()
            Try
                'check for errors in xml and replace invalid characters if needed
                docGateway = LoadXMLDoc(Server.MapPath("//XML/Gateway.xml"))
                docHotel = LoadXMLDoc(Server.MapPath("//XML/Hotel.xml"))
            Catch ex As XmlException
                lnum = ex.LineNumber
                ReplaceSpecialChars(Server.MapPath("//XML/Hotel.xml"), lnum)

                docHotel = LoadXMLDoc(Server.MapPath("//XML/Hotel.xml"))
            End Try
            Response.Write("Xml Created on time " & Date.Now.ToString)
        Catch er As XmlException
            Response.Write("Xml could not be created " & er.Message)
        Catch er As HttpException
            Response.Write("Xml could not be created " & er.Message)
        Catch er As Exception
            Response.Write("Xml could not be created " & er.Message)
        End Try

When i run it. It gives me an error message which says:
Xml could not be created Access to the path 'F:\websites\local\dreamvacations\XML\Hotel.xml' is denied.

xmlGateway = New StreamWriter(Server.MapPath("//Gateway.xml"), False)

The above line works fine and create Gateway.xml on root directory which is a network directory(F:\websites\local\dreamvacations) and the web address for this is: http://192.168.0.29 

Also tried the below line:
xmlGateway = New StreamWriter(Server.MapPath("http://192.168.0.29/XML/Gateway.xml"), False)

Doesn't work. Any help please....:(
0
Comment
Question by:shwaqar82
  • 3
  • 2
6 Comments
 
LVL 35

Accepted Solution

by:
YZlat earned 250 total points
ID: 17798586
1) open your web.config file and add the following line
<identity impersonate="true"/>

after

<authentication mode="Windows" />

2) open IIS, navigate to your application. Right-click on it and go to Directory Security tab. In Anonymous Access click on Edit button. Uncheck Anonymous Access checkbox and make sure Integrated Windows authentication is checked

3) give ASPNET user permissions to 'F:\websites\local\dreamvacations\XML\Hotel.xml'
0
 

Author Comment

by:shwaqar82
ID: 17798801
wat about 3rd step ...how can i give asp.net  user an access to 'F:\websites\local\dreamvacations\XML\Hotel.xml' .

I think the user has an access to read n write. If not then how it can create xml files to root directory which is :
'F:\websites\local\dreamvacations'. Using the below code:

xmlGateway = New StreamWriter(Server.MapPath("//Gateway.xml"), False)
0
 

Author Comment

by:shwaqar82
ID: 17798828
do i have to create user name and password for asp.net user ..how can i do that...As i unchecked anonymous access
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 35

Expert Comment

by:YZlat
ID: 17798950
you don't neet to, just right-click on Hotel.xml file and select Properties. Then then go to Security tab and look for something like this in the user list:

ASP.NET Machine Acount

If you find it, select it and see if it has necessary permissions to Hotel.xml file.

If you don't see it, click on Add and Type in ASPNET and click on Check Names. Then click OK. Add the necessary permissions for that user
0
 

Author Comment

by:shwaqar82
ID: 17799013
well i cant get that exactly what ur saying ..but yae hotel.xml has read n write permissions. And this application pops up an authentication window once i change the web.congif and add additinal tag in it .

Please help me out :(
0
 
LVL 10

Assisted Solution

by:jnhorst
jnhorst earned 250 total points
ID: 17799950
Shwaqar82...

Revert the web.config settings back to where they were originally and reset IIS to authenticate anonymous requests with the default IUSR_<machine name> account.  Here is a little background...

When you <b>DO NOT /b> have an <identity impersonate="true" /> AND you are using IIS 5.x (Windows 2000), the server's local ASPNET account will be the context under which your code will run.  If you are running IIS 6.x (Windows 2003) then it will be the NETWORK SERVICE account.

If you <b>DO</b> have <identity impersonate="true" /> in web.config, then one of two things will happen.  If IIS is configured to use the IUSR_<machine name> account (or any other account) to authenticate anonymous requests, then that account will be the context in which your code will run.  If you deselect allow anonymous and select Windows Integrated, then your user will get a username/pwd prompt and assuming they have a username on your network, that will be the account used.  I take it you do not want that...

What I am wondering is whether your F drive is local to the IIS server or is a network drive.  If it is local, then you need to grant read/write privileges to the folder to which you want to write your file for either the ASPNET (Win2K) or NETWORK SERVICE (Win2003) account.

If F is a network drive, you have a  different problem...  Either ASPNET or NETWORK SERVICE is a local account to the IIS machine.  The server on which the F drive actually lives will know nothing about it.  What you are left with in that case is creating an account on your domain/AD with practically no priveleges and then set IIS to use that account to authenticate anonymous requests.  Then grant that account the needed privileges on the server that actually hosts the F drive.  You may also have to add this account as a SQL Server login if you will be accessing databases from your pages.

John
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question