【发布时间】:2011-04-17 07:05:36
【问题描述】:
我正在构建一个 ASP.NET MVC 站点,我在其中使用 Lucene.Net 进行搜索查询。我 asked a question here 关于如何在 ASP.NET MVC 应用程序中正确构建 Lucene.Net 使用,并被告知最好的方法是将我的 IndexWriter 声明为 public static,以便它可以重复使用。
这是我的 SearchController 顶部的一些代码:
public static string IndexLocation = Server.MapPath("~/lucene");
public static Lucene.Net.Analysis.Standard.StandardAnalyzer analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer();
public static IndexWriter writer = new IndexWriter(IndexLocation,analyzer);
由于writer 是静态的,IndexLocation 也必须是静态的。因此,编译器给我Server.MapPath() 的以下错误:
非静态字段、方法或属性“System.Web.Mvc.Controller.Server.get”需要对象引用
是否有使用 Server.MapPath() 或静态字段的类似方法?我该如何解决这个错误?
【问题讨论】:
标签: c# asp.net-mvc static lucene.net server.mappath