Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access to the path is denied

Posted on 2006-10-24
6
Medium Priority
?
1,217 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 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
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!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

705 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