【问题标题】:Lucene.Net fails at my host because it calls GetTempPath(). What's the work around?Lucene.Net 在我的主机上失败,因为它调用 GetTempPath()。有什么工作?
【发布时间】:2010-09-16 17:24:22
【问题描述】:

我在共享主机上的 ASP.NET 应用程序中使用 Lucene.Net。得到了如下所示的堆栈跟踪。有什么工作?

[SecurityException: 请求“System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”类型的权限失败。] System.Security.CodeAccessSecurityEngine.Check(对象需求, StackCrawlMark& stackMark, Boolean isPermSet) +0 System.Security.CodeAccessPermission.Demand() +59 System.IO.Path.GetTempPath() +54 Lucene.Net.Store.FSDirectory..cctor() +73

【问题讨论】:

    标签: asp.net permissions lucene lucene.net


    【解决方案1】:

    这是我自己问题的答案。解决方案是修改 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());
    

    在那之后还有一个安全权限障碍,这也是解决方法。我不明白为什么一种获取目录中文件名的方式会被阻止,而另一种方式不会被阻止。

        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;
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-01
      • 1970-01-01
      • 2020-08-02
      • 1970-01-01
      • 1970-01-01
      • 2015-05-19
      相关资源
      最近更新 更多