Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Access to the path is denied

Posted on 2006-10-24
6
Medium Priority
?
1,226 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 500 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

963 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