Security Error - Writing to a Text File

J

Jennifer

On an ASP page I've got some code that is supposed to "export" data in
a grid to an Excel file. What I'm doing is writing all the data to a
text file, separating the fields by commas. Then I'll redirect the
user to a new page with the file that was just created.

Code:

Dim objFSO, objTextFile
Dim sRead, sReadLine, sReadAll
Const ForReading = 1, ForWriting = 2, ForAppending = 8

objFSO = CreateObject("Scripting.FileSystemObject")
objTextFile = objFSO.CreateTextFile
("C:\Inetpub\wwwroot\WhatacoDailyReport\Test.CSV", True)

objTextFile.WriteLine(sFieldValues)
objTextFile.Close()
Response.Redirect("/whatacodailyreport/test.csv")

I'm getting the following error:

Security Exception
Description: The application attempted to perform an operation not
allowed by the security policy. To grant this application the required
permission please contact your system administrator or change the
application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Exception from
HRESULT: 0x800A0046 (CTL_E_PERMISSIONDENIED).

The program errors out on the CreateObject line.

Now, here's what I've done to try to fix it:

I've turned off anonymous access by taking the following steps:

1. Right click on My Computer and select "Manage"
2. Expand "Services and Applications" in the Tree View
3. Expand "Internet Information Services"
4. Expand "Web Site"
5. Expand "Default Web Site"
6. Right click on your application and select "Properties"
7. Select the "Directory Security" tab
8. Click the "Edit..." button
9. Uncheck "Anonymous Access"

Under the Directory tab I've checked Script Source Access, Read,
Write, Log Visits and Index This Resource. Also, under Application
Settings I was not sure what, if anything, to change.

Also, this is my own personal computer, so why am I denied access?

Any suggestions would be helpful.

Thanks,
Jennifer
 
J

Jason

Try going into Internet Explorer (Tools->Internet Options->Security) and
changing the security level for "Local intranet". I would try switching it
to Low and see if your code runs; if it does you could then monkey around
with the specifics via the "Custom Level" button if you want (though I don't
think it matters for your situation).
 
J

Jennifer

Jason,

Thanks for replying. Your suggestion didn't work. :(

I know there has got to be a solution - I see this kind of thing on
other web pages where someone exports something to Excel. And I'm not
really trying for Excel - even Notepad would be fine. :)

Anybody else have any suggestions?

Thanks,
Jennifer
 
P

Paul Clement

On 12 Aug 2004 11:50:53 -0700, (e-mail address removed) (Jennifer) wrote:

¤ On an ASP page I've got some code that is supposed to "export" data in
¤ a grid to an Excel file. What I'm doing is writing all the data to a
¤ text file, separating the fields by commas. Then I'll redirect the
¤ user to a new page with the file that was just created.
¤
¤ Code:
¤
¤ Dim objFSO, objTextFile
¤ Dim sRead, sReadLine, sReadAll
¤ Const ForReading = 1, ForWriting = 2, ForAppending = 8
¤
¤ objFSO = CreateObject("Scripting.FileSystemObject")
¤ objTextFile = objFSO.CreateTextFile
¤ ("C:\Inetpub\wwwroot\WhatacoDailyReport\Test.CSV", True)
¤
¤ objTextFile.WriteLine(sFieldValues)
¤ objTextFile.Close()
¤ Response.Redirect("/whatacodailyreport/test.csv")
¤
¤ I'm getting the following error:
¤
¤ Security Exception
¤ Description: The application attempted to perform an operation not
¤ allowed by the security policy. To grant this application the required
¤ permission please contact your system administrator or change the
¤ application's trust level in the configuration file.
¤
¤ Exception Details: System.Security.SecurityException: Exception from
¤ HRESULT: 0x800A0046 (CTL_E_PERMISSIONDENIED).
¤
¤ The program errors out on the CreateObject line.
¤
¤ Now, here's what I've done to try to fix it:
¤
¤ I've turned off anonymous access by taking the following steps:
¤
¤ 1. Right click on My Computer and select "Manage"
¤ 2. Expand "Services and Applications" in the Tree View
¤ 3. Expand "Internet Information Services"
¤ 4. Expand "Web Site"
¤ 5. Expand "Default Web Site"
¤ 6. Right click on your application and select "Properties"
¤ 7. Select the "Directory Security" tab
¤ 8. Click the "Edit..." button
¤ 9. Uncheck "Anonymous Access"
¤
¤ Under the Directory tab I've checked Script Source Access, Read,
¤ Write, Log Visits and Index This Resource. Also, under Application
¤ Settings I was not sure what, if anything, to change.
¤
¤ Also, this is my own personal computer, so why am I denied access?
¤
¤ Any suggestions would be helpful.

See if the following helps:

PRB: "Access Denied" Error Message Occurs When You Impersonate an Account in ASP.NET and Then Call
STA COM Components
http://support.microsoft.com/default.aspx?scid=kb;en-us;325791


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top