Cannot use Server.MapPath

2019-01-16 13:24发布

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?

6条回答
太酷不给撩
2楼-- · 2019-01-16 13:51

Firt add a reference to System.web, if you don't have. Do that in the References folder.

You can then use Hosting.HostingEnvironment.MapPath(path);

查看更多
Summer. ? 凉城
3楼-- · 2019-01-16 14:06

Your project needs to reference assembly System.Web.dll. Server is an object of type HttpServerUtility. Example:

HttpContext.Current.Server.MapPath(path);
查看更多
劫难
4楼-- · 2019-01-16 14:07

you can try using this

    System.Web.HttpContext.Current.Server.MapPath(path);

or use HostingEnvironment.MapPath

    System.Web.Hosting.HostingEnvironment.MapPath(path);
查看更多
▲ chillily
5楼-- · 2019-01-16 14:09

You need to add reference (System.Web) Reference to System.Web

查看更多
孤傲高冷的网名
6楼-- · 2019-01-16 14:11

System.Web.HttpContext.Current.Server.MapPath("~/") gives null if we call it from a thread.

So, Try to use

System.Web.Hosting.HostingEnvironment.MapPath("~/")

查看更多
做个烂人
7楼-- · 2019-01-16 14:14

Try adding System.Web as a reference to your project.

查看更多
登录 后发表回答