Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I used the following lines (or variants thereof) to create a file in output mode:

 

Dim writer As StreamWriter

writer = New StreamWriter(Request.PhysicalApplicationPath & "NewFile.txt", False)

 

Whether the file exists or not, I receive the following runtime error:

 

 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

 

Exception Details: System.UnauthorizedAccessException: Access to the path "c:\inetpub\wwwroot\KICMG\WebApplication1\NewFile.txt" is denied.

 

The ASP.NET process is not authorized to access the requested resource. For security reasons the default ASP.NET process identity is '{machinename}\ASPNET', which has limited privileges. Consider granting access rights to the resource to the ASP.NET process identity.

 

To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the "{machinename}\ASPNET" user. Highlight the ASP.NET account, and check the Write box in the Allow column.

 

 

 

 

When I attempt to follow the instructions in the last paragraph above, I do not get a Security tab in Properties. Can anyone suggest a solution to this problem? Thanks.

  • Moderators
Posted

Is this on a hosted server or your own machine?

 

Just so you know, PhysicalApplicationPath gets the physical directory and path on the HDD.

It may be better to do something like this....

 

 

Dim sPath As String = Server.MapPath("WebApplication1")
'I wrote 'WebApplication1' because that is the name of you project (you posted above).

Visit...Bassic Software
Posted

Roddy: I tried that using the following code:

 

Dim sPath As String = Server.MapPath("WebApplication2")

Dim writer As StreamWriter

TextBox1.Text = sPath

writer = New StreamWriter(sPath & "NewFile1.txt", False)

writer.WriteLine("This works.")

writer.Close()

 

 

The textbox printed sPath as

 

c:\inetpub\wwwroot\WebApplication2\WebApplication2

 

However, there were no files or sub-subdirectories produced nor were any errors produced. Any idea where the file is created? Thanks.

Posted

Robby:

 

Adding the slash produces the follwoing error:

 

Could not find a part of the path "c:\inetpub\wwwroot\WebApplication2\WebApplication2\NewFile1.txt".

 

 

My original code leads to the correct file, but somewhow the access to open a file in the output mode is denied and I don't know how to change that.

 

Thanks.

Posted

Robby:

 

Thanks for your effort. My original code was fine. The change in write-access setting had to be done through the IIS menus. When I did that the original code worked fine.

  • 4 weeks later...
  • *Experts*
Posted

Sorry to dig up this thread, but I'm having the same problem,

only with trying to open a file for reading.

 

How do I change the IIS settings to allow file reading?

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

Bucky:

 

It has been sometime since I changed the settings. But try this:

 

Through control panel (>> Admin. tools >> IIS >> Local computer >> Default web site) reach the Default web site icon. Right click on the icon and click properties. Within properties, select Home Directory tab. You should be able to reset the read and write privileges for files.

 

Good luck. Let me know if this works.

  • 2 months later...
Posted

I don't know if you ever got this fixed but you need to enable impersonation.

 

add a line similar to this in your web.config

 

<identity impersonate="true" userName="<userid>" password="<password>"/>

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...