Lucene.Net fails at my host because it calls GetTempPath(). What#39;s the work around?(Lucene.Net 在我的主机上失败,因为它调用 GetTempPath().有什么工作?)
问题描述
我在共享主机上的 ASP.NET 应用程序中使用 Lucene.Net.得到了如下所示的堆栈跟踪.有什么工作?
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?
[SecurityException: 请求System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"类型的权限失败.]System.Security.CodeAccessSecurityEngine.Check(对象需求, StackCrawlMark& stackMark, Boolean isPermSet) +0System.Security.CodeAccessPermission.Demand() +59System.IO.Path.GetTempPath() +54Lucene.Net.Store.FSDirectory..cctor() +73
[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
推荐答案
这是我自己问题的答案.解决方案是修改 Lucene.Net.Store.FSDirectory,通过注释掉这个未使用的行:
Here's the answer to my own question. The solution was to modify Lucene.Net.Store.FSDirectory, by commenting out this unused line:
// 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;
}
这篇关于Lucene.Net 在我的主机上失败,因为它调用 GetTempPath().有什么工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Lucene.Net 在我的主机上失败,因为它调用 GetTempPath().有什么工作?


基础教程推荐
- 如果条件可以为空 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 将数据集转换为列表 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01