创建于中等信任环境的目录? [英] Creating directories in medium trust environment?

查看:211
本文介绍了创建于中等信任环境的目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在一个共享的托管服务提供商中等信任环境中运行ASP.NET Web应用程序。下面code会导致抛出一个SecurityException:

I've got an ASP.NET Web Application running in a medium trust environment with a shared hosting provider. The following code causes a SecurityException to be thrown:

private void TestButton_Click(object sender, EventArgs e)
{
    string directory = Server.MapPath("~/MyFolder/") + "_TestDirectory";
    if (!Directory.Exists(directory))
        Directory.CreateDirectory(directory);
}

错误的全文是:

System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
   at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
   at System.Security.CodeAccessPermission.Demand()
   at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, DirectorySecurity dirSecurity)
   at System.IO.Directory.CreateDirectory(String path, DirectorySecurity directorySecurity)
   at ASP.testcreatedirectory_aspx.TestButton_Click(Object sender, EventArgs e)
The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.Permissions.FileIOPermission
The Zone of the assembly that failed was:
MyComputer

在正在创建的子文件夹具有完全的权限,所以我不认为这是问题。这看起来就像是与一个中等信任环境中运行。

The folder where the subfolder is being created has full permissions, so I don't think that's the problem. This looks like something to do with running in a medium trust environment.

这是正常的中等信任环境不允许的新目录的创建(通过Directory.Create法),和/或有什么解决方法呢?

Is it normal for medium trust environments to disallow the creation of new directories (via the Directory.Create method), and/or is there any workaround for this?

推荐答案

只要您试图访问的路径下的虚拟目录应用程序是,你应该能够访问它在中等信任。你确定你的应用程序身份文件夹中创建的权限?

As long as the path you are trying to access is under the Virtual Directory your application is in, you should be able to access it in Medium Trust. Are you sure your application identity has folder create permission?

http://msdn.microsoft.com/en-us/library/ aa302425#c09618429_015

编辑:我可能读了上面的错误文档。看到此链接,以及,看来你只有读,写,追加和PathDiscovery权限:(

I might have read the doc above wrong. See this link as well, it appears you only have Read, Write, Append, and PathDiscovery permissions :(

的FileIOPermission被限制。这个
  也就是说你只能访问文件
  应用程序的虚拟目录
  层次结构。您的申请获得批准
  读,写,追加和PathDiscovery
  为您的应用程序的权限
  虚拟目录层次结构。

FileIOPermission is restricted. This means you can only access files in your application's virtual directory hierarchy. Your application is granted Read, Write, Append, and PathDiscovery permissions for your application's virtual directory hierarchy.

http://msdn.microsoft.com/en-us/library/ ff648344.aspx

这篇关于创建于中等信任环境的目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆