Solved

Access to the path is denied

Posted on 2006-10-24
6
1,212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Industry Leaders: 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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

624 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