I'm using Lucene.Net in an ASP.NET application on a shared host. Got this stack trace shown below. What's the work around?
我在共享主机上的ASP.NET应用程序中使用Lucene.Net。得到如下所示的堆栈跟踪。有什么工作?
[SecurityException: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.] System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0 System.Security.CodeAccessPermission.Demand() +59 System.IO.Path.GetTempPath() +54 Lucene.Net.Store.FSDirectory..cctor() +73
[SecurityException:请求类型'System.Security.Permissions.EnvironmentPermission,mscorlib,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'的权限失败。] System.Security.CodeAccessSecurityEngine.Check(Object demand,StackCrawlMark&stackMark ,Boolean isPermSet)+0 System.Security.CodeAccessPermission.Demand()+59 System.IO.Path.GetTempPath()+54 Lucene.Net.Store.FSDirectory..cctor()+73
1 个解决方案
#1
2
Here's the answer to my own question. The solution was to modify Lucene.Net.Store.FSDirectory, by commenting out this unused line:
这是我自己的问题的答案。解决方案是通过注释掉这个未使用的行来修改Lucene.Net.Store.FSDirectory:
// Comments out by Corey Trager, Oct 2008 to workaround permission restrictions at shared host. This is not used.
// public static readonly System.String LOCK_DIR = SupportClass.AppSettings.Get("Lucene.Net.lockDir", System.IO.Path.GetTempPath());
There was one more security permission hurdle after that, and here's that workaround too. I don't understand why one way of getting the names of files in a directory would be blocked, and another way not blocked.
之后还有一个安全许可障碍,这也是解决方法。我不明白为什么一种获取目录中文件名称的方法会被阻止,另一种方法不会被阻止。
public override System.String[] List()
{
/* Changes by Corey Trager, Oct 2008, to workaround permission restrictions at shared host */
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(directory.FullName);
System.IO.FileInfo[] files = dir.GetFiles();
string[] list = new string[files.Length];
for (int i = 0; i < files.Length; i++)
{
list[i] = files[i].Name;
}
return list;
/* end of changes */
// System.String[] files = SupportClass.FileSupport.GetLuceneIndexFiles(directory.FullName, IndexFileNameFilter.GetFilter());
// for (int i = 0; i < files.Length; i++)
// {
// System.IO.FileInfo fi = new System.IO.FileInfo(files[i]);
// files[i] = fi.Name;
// }
// return files;
}
#1
2
Here's the answer to my own question. The solution was to modify Lucene.Net.Store.FSDirectory, by commenting out this unused line:
这是我自己的问题的答案。解决方案是通过注释掉这个未使用的行来修改Lucene.Net.Store.FSDirectory:
// Comments out by Corey Trager, Oct 2008 to workaround permission restrictions at shared host. This is not used.
// public static readonly System.String LOCK_DIR = SupportClass.AppSettings.Get("Lucene.Net.lockDir", System.IO.Path.GetTempPath());
There was one more security permission hurdle after that, and here's that workaround too. I don't understand why one way of getting the names of files in a directory would be blocked, and another way not blocked.
之后还有一个安全许可障碍,这也是解决方法。我不明白为什么一种获取目录中文件名称的方法会被阻止,另一种方法不会被阻止。
public override System.String[] List()
{
/* Changes by Corey Trager, Oct 2008, to workaround permission restrictions at shared host */
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(directory.FullName);
System.IO.FileInfo[] files = dir.GetFiles();
string[] list = new string[files.Length];
for (int i = 0; i < files.Length; i++)
{
list[i] = files[i].Name;
}
return list;
/* end of changes */
// System.String[] files = SupportClass.FileSupport.GetLuceneIndexFiles(directory.FullName, IndexFileNameFilter.GetFilter());
// for (int i = 0; i < files.Length; i++)
// {
// System.IO.FileInfo fi = new System.IO.FileInfo(files[i]);
// files[i] = fi.Name;
// }
// return files;
}