Lucene.Net在我的主机失败,因为它调用GetTempPath()。什么是变通? [英] Lucene.Net fails at my host because it calls GetTempPath(). What's the work around?

查看:246
本文介绍了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程序,版本= 2.0.0.0,文化=中性公钥= b77a5c561934e089'失败。]
   System.Security codeAccessSecurityEngine.Check(对象的需求,StackCrawlMark&安培; stackMark,布尔isPermSet)+0
   System.Security。codeAccessPermission.Demand()+59
   System.IO.Path.GetTempPath()+54
   Lucene.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()。什么是变通?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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