server.mappath

C# Unit Testing: Testing a method that uses MapPath

丶灬走出姿态 提交于 2019-12-03 04:55:20
First of all, I am aware that this question is dangerously close to: How to MapPath in a unit test in C# I'm hoping however, that it has a different solution. My issue follows: In my code I have an object that needs to be validated. I am creating unit tests for each validation method to make sure it is validating correctly. I am creating mock data and loading it into the object, then validating it. The problem is that within the validation, when an error occurs, an error code is assigned. This error code is used to gather information about the error from an xml file using Server.MapPath.

Map the physical file path in asp.net mvc

好久不见. 提交于 2019-12-02 20:02:37
I am trying to read an XSLT file from disk in my ASP.Net MVC controller. What I am doing is the following: string filepath = HttpContext.Request.PhysicalApplicationPath; filepath += "/Content/Xsl/pubmed.xslt"; string xsl = System.IO.File.ReadAllText(filepath); However, half way down this thread on forums.asp.net there is the following quote HttpContext.Current is evil and if you use it anywhere in your mvc app you are doing something wrong because you do not need it. Whilst I am not using Current , I am wondering what is the best way to determine the absolute physical path of a file in MVC?

Server.MapPath()

∥☆過路亽.° 提交于 2019-12-01 19:50:26
问题 I want to use Server.MapPath() method im order to map a virtual directory I created to its physical path. The thing is that the .net environment doesn't recognize Server.MapPath(). Google told me I'm supposed to use HttpContext.Current.Server using System.Web, but HttpContext isn't recognized in spite of me using System.Web. (And I've checked - HttpContext IS one of System.Web's classes) Help? 回答1: Make sure you have included System.Web in your projects References Do these (In Visual Studio

Server.MapPath()

旧巷老猫 提交于 2019-12-01 18:21:53
I want to use Server.MapPath() method im order to map a virtual directory I created to its physical path. The thing is that the .net environment doesn't recognize Server.MapPath(). Google told me I'm supposed to use HttpContext.Current.Server using System.Web, but HttpContext isn't recognized in spite of me using System.Web. (And I've checked - HttpContext IS one of System.Web's classes) Help? Make sure you have included System.Web in your projects References Do these (In Visual Studio IDE): Right click on the Project Node (Solution Explorer Window) On the context mennu, click Add Reference

Using Server.MapPath in MVC3

廉价感情. 提交于 2019-11-30 11:03:53
问题 I have the code string xsltPath = System.Web.HttpContext.Current.Server.MapPath(@"App_Data") + "\\" + TransformFileName It returns C:\inetpub\wwwroot\websiteName\SERVICENAME\App_Data\FileName.xsl Why am I getting the path to the ServiceController, SERVICENAME ? I want the path to App_Data which is in C:\inetpub\wwwroot\websiteName\App_Data\FileName.xsl 回答1: You need to specify that you want to start from the virtual root: string xsltPath = Path.Combine(System.Web.HttpContext.Current.Server

Using Server.MapPath in MVC3

青春壹個敷衍的年華 提交于 2019-11-29 23:03:29
I have the code string xsltPath = System.Web.HttpContext.Current.Server.MapPath(@"App_Data") + "\\" + TransformFileName It returns C:\inetpub\wwwroot\websiteName\SERVICENAME\App_Data\FileName.xsl Why am I getting the path to the ServiceController, SERVICENAME ? I want the path to App_Data which is in C:\inetpub\wwwroot\websiteName\App_Data\FileName.xsl You need to specify that you want to start from the virtual root: string xsltPath = Path.Combine(System.Web.HttpContext.Current.Server.MapPath(@"~/App_Data"), TransformFileName); Additionally, it's better practice to use Path.Combine to combine

How can I use Server.MapPath() from global.asax?

二次信任 提交于 2019-11-29 18:54:11
I need to use Server.MapPath() to combine some files path that I store in the web.config . However, since Server.MapPath() relies on the current HttpContext (I think), I am unable to do this. When trying to use the method, even though its "available", I get the following exception: Server operation is not available in this context. Is there another method that can map a web root relative directory such as ~/App_Data/ to the full physical path such as C:\inetpub\wwwroot\project\App_data\ ? You could try System.Web.Hosting.HostingEnvironment.MapPath() . No HttpContext required. Kiran Banda Use

Server.Mappath in C# classlibrary

懵懂的女人 提交于 2019-11-28 19:04:49
How can i use the server.mappath method in a C# class library class ,which acts as my BusinessLayer for My ASP.NET WEbsite By calling it? var path = System.Web.HttpContext.Current.Server.MapPath("default.aspx"); Make sure you add a reference to the System.Web assembly. You can get the base path by using the following code and append your needed path with that. string path = System.AppDomain.CurrentDomain.BaseDirectory; You should reference System.Web and call: HttpContext.Current.Server.MapPath(...) Maybe you could abstract this as a dependency and create an IVirtualPathResolver. This way your

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

不问归期 提交于 2019-11-28 17:07:40
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 Lucene.Net.Analysis.Standard.StandardAnalyzer(); public static IndexWriter writer = new IndexWriter

Cannot use Server.MapPath

↘锁芯ラ 提交于 2019-11-27 17:45:58
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? DotNetUser you can try using this System.Web.HttpContext.Current.Server.MapPath(path); or use HostingEnvironment.MapPath System.Web.Hosting.HostingEnvironment.MapPath(path); Leandro Gomide Your project needs to reference assembly System.Web.dll . Server is an object of type HttpServerUtility . Example: HttpContext.Current.Server.MapPath(path); Ravindra Singh Chhabra System.Web.HttpContext.Current.Server.MapPath("~/") gives