473,378 Members | 1,507 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Security exception in HttpPostedFile.SaveAs in medium trust servers

I am trying to access a folder which resides outside the application.My application hosted in a medium trust level server. I am getting error in the below line of code.

brandImage.PostedFile.SaveAs("C:\Temp" + sFileName);

My application is in c:\Inetpub\wwwroot.


Please see the below exception

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.


Please help....

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Jan 11 '07 #1
2 2447
I am trying to access a folder which resides outside the application.My application hosted in a medium trust level server.
The default Medium trust policy grants web applications access only to files in their own virtual directories. See the file %windir%\Microsoft.NET\Framework\%version%\CONFIG\ web_mediumtrust.config. The FileIOPermission is limited to $AppDir$. Your hosting provider is unlikely to grant you access to any other folder.

You have to explicitly grant permission, even to *read* files in the application. I'm still having trouble writing files, and that's how I stumbled onto this thread. I've had success with System.IO.File.AppendAllText, but I have the same problem with HttpPostedFile.SaveAs.

Try some simpler file-write tests first to make sure that you at least have the requisite permissions set, even in your own directory. Your hosting company may provide a web interface that lets you create application-readable and -writeable folders (because you can't do this through FTP to a Windows server).

Good luck!
Jan 22 '08 #2
jhaxo
57
This is interesting. I just did my first web app which accessed files outside the inetpub/wwwroot/app dir. I used cacls to give access to IUSR_machinename and NETWORK SERVICE, as well as IWAM and ASPNET for good measure but I think the last 2 were not needed.

In my case I have access to a test server, and in part because we are behind a firewall, the admin is allowing these changes for the production server as well.
Jan 22 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: Diego F. | last post by:
I think I'll never come across that error. It happens when running code from a DLL that tries to write to disk. I added permissions in the project folder, the wwwroot and in IIS to NETWORK_SERVICE...
3
by: CyberLotus | last post by:
Hi, I've created a web application and through this I want to import Excel data to database. Following is the code that I've written, ...
5
by: wenning | last post by:
Hello, I am struggling with a website on a W2K3 server which has the actual content on a NAS server (also W2K3 based). The servers doesn't run in a domain and arent intended to. I did make...
10
by: David Thielen | last post by:
Hi; I am trying to write to the event log using: public const string EVENT_LOG_NAME = "Windward Portal"; if (!EventLog.SourceExists(EVENT_LOG_NAME)) EventLog.CreateEventSource(EVENT_LOG_NAME,...
0
by: AmitKu | last post by:
I am trying to do a URL post using HttpWebRequest, but it fails because I am hosting on Network Solutions, and their servers are all medium trust. Apparently HttpWebRequest doesn't work on medium...
0
by: AmitKu | last post by:
I am trying to do a URL post using HttpWebRequest, but it fails because I am hosting on Network Solutions, and their servers are all medium trust. Apparently HttpWebRequest doesn't work on medium...
7
by: AmitKu | last post by:
I am trying to do a URL post using HttpWebRequest, but it fails because I am hosting on Network Solutions, and their servers are all medium trust. Apparently HttpWebRequest doesn't work on medium...
0
by: alf | last post by:
I have an app that was running in my local server using full trust, now I moved it to hosting company wish run in Medium trust. Then I get a Security exception (details below) Then I configured...
1
by: Spanco | last post by:
In my Application ,When I am hosted my application , that gives an error.... "Exception: System.Security.SecurityException:That assembly does not allow partially trusted callers. Description:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.