Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am facing some problem with file upload control in asp.net 2.0..while uploading a file onto the server.this is all working fine on the local development machine.but giving problem on the web server after deployment..the error goes something like this..
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. [ Security Exception ]All the write permissions are given to the folders on web server..
If any one has idea on how to chase it please
Thanks
Srenvas

1) Check to make sure both the IIS and ASP accounts have create file access to the directories in question.
2) Check to make sure the paths are valid for the production machine.
3) Check the production server's configuration for the app, and make sure the server allows file uploads. I'd give you more specific answer for this step, but I'm not near a machine with IIS installed.

Thnks Razor2.3
1 ) the root directory has full access for write permission.
2 ) the paths are correct as i am using ~/ for accessing the folder
3 ) This is where i am not able to get the point. How do i know whether the production server would allow file upload or not. bcoz the exception is as follows and is clear that its not getting the permissions and i hve written the issue to the production server support team and they say we cant help in this regard :-( dnt know wht to doSecurity 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: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Source Error:
Line 32: End If
Line 33:
Line 34: Dim fi As New IO.FileInfo(fuImage.PostedFile.FileName)
Line 35: objServices.ServiceImage = fi.Extension
Line 36: Dim PhotoId As Integer = objServicesBO.InsertMrservices(objServices)
Source File: d:\hosting\imrshop\projects\mrcentre\Admin\ManageServices.aspx.vb Line: 34
From this can you pls make out anything and tell me wht is the bug or the problem with the server. I feel that the permissions for hte domain are managed by the machine levle config file ? am i right
Thanks
Srenvas

~/ is a *NIX standard and not a Windows standard, so you can't use it [reliably].
To get the current directory, you could try .\, but I've had limited success with it. The best bet would be to use the full Windows path.
.NET will tell you the executing directory; it's somewhere in System.Reflection.
A quick MSDN search turned up this bit of code:
Dim path As String
path = System.IO.Path.GetDirectoryName( _
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)

ok i have used ur method of mapping the file path , still does not work. now the question is how to manage to know if the server is allowing upload of files from my application.
Thanks
Srenvas

Thnks for that , ok for this i think i need access to the webserver directly ,but my server is an hosting company and i host my application using ftp and config it on the control panel, the solution which you have provided should solve the problem i think , but i dnt have access to the webserver i have talked to the support team and they said they cant allow me access to the server :-( i am in trouble again..soory can u help me in any other way anything where i can change my application level config file and make the thing work
Thnks
Thanks
Srenvas

Well, you should be able to see if a file does upload; it's crashing after you issued a fuImage.PostedFile.SaveAs(String), so it's just a matter of FTP'ing into the server, and see if anything's there. If not, you can just issue one for debug purposes.
It looks like it's crashing because it can't get the (potential) file permissions, which could be caused by security being set too high, or security being set reasonably (for ASP), and the path being malformed.
If you're creating an IO.FileInfo just to grab the extension, there are easier ways to do it. Personally, I like:
int iExt = fuImage.Value.LastIndexOf(".") + 1
If iExt Then
objServices.ServiceImage = fuImage.Value.Substring(iExt)
...

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |