How to get absolute path in ASP.Net Core alternative way for Server.MapPath

前端 未结 5 1571
野的像风
野的像风 2020-12-02 18:39

How to get absolute path in ASP net core alternative way for Server.MapPath

I have tried to use IHostingEnvironment

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-02 18:59

    * Hack * Not recommended, but FYI you can get an absolute path from a relative path with var abs = Path.GetFullPath("~/Content/Images/Sample.PNG").Replace("~\\","");

    Prefer the DI/Service approaches above, but if you are in a non-DI situation (e.g., a class instantiated with Activator) this will work.

提交回复
热议问题