File Upload using ASP.NET in Medium Trust

Discussion in 'Microsoft Development' started by unicode, Aug 20, 2010.

  1. unicode

    unicode Guppy

    Has anyone been able to successfully deploy file upload in medium trust config. It would be really nice - if they could upload a sample code file / config or instructions on going about doing the same ...

    Code - in ASP.NET (c#) - would be really helpful ! ... Image upload is a generic feature of any dynamic site ... and it would be really nice if someone has done it and can help with the same ...
  2. Stephen

    Stephen US Operations Staff Member

    Mojoportal does uploads in medium trust really well, I haven't done a code breakdown but it works every time :D
  3. unicode

    unicode Guppy

    Yeah Stephen ...

    Dun know - am unable to replicate the same in our program ...

    Am wondering - if someone has used a file upload in medium trust - and can post the code snippet - would be really super helpful ! ...
  4. Stephen

    Stephen US Operations Staff Member

    I found an AJAX upload tool that works in medium trust:

    the main issue is to ensure you are using relative paths and not hard coded paths, or physical paths, if you use a physical path or a mappath that reads like d:\hshome\user\domain\folder\foldertoupload, it is 100% going to fail every time.

    Here is a more complete example using a flash based uploader with backend designed for medium trust level.
  5. largerabbit

    largerabbit Perch

    I have several sites that all upload using the standard methods.

    What errors are you getting? I think you need support to make the upload directory writeable as well.


  6. Stephen

    Stephen US Operations Staff Member

    We've done that, it is system permissions errors, about trust level not able to access d:\, so it isn't using the virtual path.
  7. unicode

    unicode Guppy

    Yeah ... even after putting the paths rights - we get the exception.

    I am sure someone is using File Upload in a Medium Trust - if anyone can help - will be awesome !

    Below is a copy paste of the 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: Request failed.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [SecurityException: Request failed.]
    System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed) +150
    System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed) +100
    System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Object assemblyOrString, SecurityAction action, Boolean throwException) +284
    System.Security.PermissionSetTriple.CheckSetDemand(PermissionSet demandSet, PermissionSet& alteredDemandset, RuntimeMethodHandle rmh) +69
    System.Security.PermissionListSet.CheckSetDemand(PermissionSet pset, RuntimeMethodHandle rmh) +150
    System.Security.PermissionListSet.DemandFlagsOrGrantSet(Int32 flags, PermissionSet grantSet) +30
    System.Threading.CompressedStack.DemandFlagsOrGrantSet(Int32 flags, PermissionSet grantSet) +40
    System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant, CompressedStack securityContext) +123
    System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant) +54
  8. unicode

    unicode Guppy

    Can u put up a sample code please - a simple stuff which works - which we can try and use - in c# medium trust environment ...

    We've tried almost everything ... we could find on the net ! ...

    Most sites needs basic image upload functionality - and we are getting stuck in there ....

    Help will be highly appreciated :)


Share This Page

JodoHost - 26,000 hosting end-users in 100 countries
Plesk Web Hosting
VPS Hosting
H-Sphere Web Hosting
Other Services