Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trust Level Error

Status
Not open for further replies.

kennyaidan

Programmer
Apr 9, 2003
54
IE
Hi,
I am trying to create aspx files and folders on an IIS server and i got 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 code i used was
outputfile = fso.CreateTextFile("C:\Inetpub\ & storydate & "\" & storyfile & ".aspx", True)

Does anyone know how to change the trust level permissions on an IIS server so that i am able to create files and folders on it. At the moment the trust level within the machine.config file is set to "high". I have tried setting that to low and i still get the same error. Any help greatly appreciated.
Thanks
Aidan
 
Is this on a .NET server (.aspx) and are you trying to create the folders at the same time as the textfile?



Chris.


Indifference will be the downfall of mankind, but who cares?
 
Yes it is on a .NET server and i tried to create the folders before I create files in the code. The create folder code comes first in the file, it checks that this folder doesn't exist already and if not it then creates a new directory

If Not fso.FolderExists("C:\Inetpub\ & storydate) Then
f = fso.CreateFolder("C:\Inetpub\ & storydate)

then further down the code it creates a new aspx file to be placed into the newly created folder.

outputfilex = fso.CreateTextFile("C:\Inetpub\ & storydate & "\" & storyfile & ".aspx", True)

The error message appears at the create folder section doesn't even get down to the create file piece of code.

thanks
aidan
 
Not got into .net yet, but in the code you posted the "\"is missing from the fso.CreateFolder(...\news & storydate)

try this, (works for IIS5)

Dim AbsPath
'creating folder,
AbsPath = Server.MapPath("news") & chr(92) & storydate
If Not FSO.FolderExists(AbsPath ) then
FSO.CreateFolder(AbsPath )
End If

'create text file,
AbsPath = Server.MapPath("news")
set OutputFile = FSO.CreateTextFile(AbsPath & chr(92) & storydate & chr(92) & storyfile & ".aspx",True)

I found that with IIS I had to use '& chr(92) &' in
place '& "\" & '

Chris.


Indifference will be the downfall of mankind, but who cares?
 
Thanks Chris but i got an erro when i tried running that code - Line 51

Line 49: AbsPath = Server.MapPath("news") & chr(92) & storydate
Line 50: If Not fso.FolderExists(AbsPath) then
Line 51: fso.CreateFolder(AbsPath)
Line 52: End If

Exception from HRESULT: 0x800A004C (CTL_E_PATHNOTFOUND).

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.IO.DirectoryNotFoundException: Exception from HRESULT: 0x800A004C (CTL_E_PATHNOTFOUND).

Do i need to declare Server.MapPath somewhere
 
Server.MapPath is a standard method for getting the absolute path to the folder or so doesn't need to be declared. I am assuming that M$ have not taken some of these methods out in their efforts to shape the world the .net way.

The only thing I can think of right now is to look at the NTFS permissions for the C:\Inetpub folder tree, and to make sure that the Anonymous username (usually IUSR_computername) has permission to write to and create folders and files in the subfolders.

maybe should have thought of that first!

Chris.


Indifference will be the downfall of mankind, but who cares?
 
thanks chris for the help i just went into the inetpub directory and made all the folders read write and that solved the problem. Thanks again
aidan
 
Aidan.


Trust me to see the obvious eventually LOL.



Chris.


Indifference will be the downfall of mankind, but who cares?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top