Friday, February 20, 2015

Server.MapPath in MVC - HostingEnvironment.MapPath

Server.MapPath is throwing error in MVC? use HostingEnvironment.MapPath instead.

HostingEnvironment.MapPath needs to include to use System.Web.Hosting.

Following is the sample code:

var file = System.IO.File.AppendText(System.Web.Hosting.HostingEnvironment.MapPath("~/logs/error.txt"));

1 comment: