How Can I Find The Path To A Folder from a Controller Constructor in ASP.NET MVC?

后端 未结 3 891
野的像风
野的像风 2021-02-13 15:30

I am trying to get the path to a folder in my website root and save it to a class property when my controller constructor is called:

public TestController:Contro         


        
3条回答
  •  被撕碎了的回忆
    2021-02-13 16:00

    Try going through the ControllerContext. Forgive my syntax, but it should something like this:

    base.[Controller?]Context.HttpContext.Server.MapPath();
    

    If Server is still null in that situation, are you running outside of a web request (ie. in a test)?

提交回复
热议问题