server.mappath

Server.Mappath in C# classlibrary

梦想的初衷 提交于 2019-11-27 11:25:31
问题 How can i use the server.mappath method in a C# class library class ,which acts as my BusinessLayer for My ASP.NET WEbsite 回答1: By calling it? var path = System.Web.HttpContext.Current.Server.MapPath("default.aspx"); Make sure you add a reference to the System.Web assembly. 回答2: You can get the base path by using the following code and append your needed path with that. string path = System.AppDomain.CurrentDomain.BaseDirectory; 回答3: You should reference System.Web and call: HttpContext

Using Server.MapPath() inside a static field in ASP.NET MVC

China☆狼群 提交于 2019-11-27 10:12:09
问题 I'm building an ASP.NET MVC site where I'm using Lucene.Net for search queries. I asked a question here about how to properly structure Lucene.Net usage in an ASP.NET MVC application and was told that the best method is to declare the my IndexWriter as public static , so that it can be re-used. Here is some code that is at the top of my SearchController: public static string IndexLocation = Server.MapPath("~/lucene"); public static Lucene.Net.Analysis.Standard.StandardAnalyzer analyzer = new

Cannot use Server.MapPath

只愿长相守 提交于 2019-11-26 19:07:44
问题 What I must do to make Server.MapPath work? I have using System.Web; what else? When I type Server there is no quick result option (intelli-sense) for Server . Any help? 回答1: you can try using this System.Web.HttpContext.Current.Server.MapPath(path); or use HostingEnvironment.MapPath System.Web.Hosting.HostingEnvironment.MapPath(path); 回答2: Your project needs to reference assembly System.Web.dll . Server is an object of type HttpServerUtility . Example: HttpContext.Current.Server.MapPath(path