本文介绍了System.Security.SecurityExcept ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

希望你做得很好。



我正在使用文件上传控件在asp.net上传pdf文件。

我在根目录下有一个特定的文档文件夹,比如〜/ PaperDocument。

对于每个新上传,我在PaperDocument下创建子目录。 />


我在下面的代码中收到错误:

Hi All,
Hope you are doing well.

I am using file upload control to upload pdf file in asp.net.
I've one specific document folder under root directory, like ~/PaperDocument.
For each new upload I am creating sub directory under the "PaperDocument".

I am getting error in following piece of code:

public void SaveAttachment(string Year, string FileName)
       {
           if (!Directory.Exists(Server.MapPath("~/PaperDocument/" + Year)))
           {
               Directory.CreateDirectory(Server.MapPath("~/PaperDocument/" + Year));
           }

           fuAttachment.SaveAs(Server.MapPath("~/PaperDocument/" + Year + "/" + FileName));
       }





此代码正在我的本地工作但在共享主机服务器上出错。





This code is working on my local but throwing an error on shared hosting server.

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 for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.





我认为这是安全问题。如果我在主机面板上为Everyone设置了完全控制(读/写权限),那么它正在运行。但是我不想这样做。

如何允许我的应用程序创建文件夹。



有谁知道这个。



I believe that this is the security issue. If I set full control(read/write permission) for Everyone on the hosting Panel then it is working. but I don't want to do this.
How can I permit my application to create folder.

Is anyone have idea about this.

推荐答案


这篇关于System.Security.SecurityExcept ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 21:19