Solved

Access to the path is denied

Posted on 2006-10-24
6
1,190 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now