Getting app root in MVC controller constructor
I need to grab the physical path to the app root in an MVC project; I use this to serve from a repository that places its items on the file system.
Alternative, I could use Dependency Injection, but I'd have the same problem; I don't have a Request
until someone calls an action, so I can't u开发者_如何学Cse Request.PhysicalApplicationPath
.
You can do this in a controller:
var root = Server.MapPath(Url.Content("~/"));
精彩评论