gpt4 book ai didi

c# - Server.MapPath 在当前上下文中不存在

转载 作者:可可西里 更新时间:2023-11-01 03:12:15 25 4
gpt4 key购买 nike

在我的 MVC4 项目中我有命名空间

prj.MVC4.Controllers

在我使用 Server.MapPath(..) 的地方没有问题并且在

prj.MVC4.Models

Server.MapPath(...) 在当前上下文中不存在。

我知道 Server.MapPath 驻留在 System.Web 中,并且使用 System.Web 将命名空间和程序集添加到类中> 并将 System.Web.dll 添加到 prj。

Ctrl + .。我正在获取 Microsoft.SqlServer 作为要添加的建议命名空间。

如何解决这个问题?

最佳答案

服务器是 Controller 的一个属性,可以在运行 Web 应用程序时在其他地方访问它

System.Web.HttpContext.Current.Server

关于c# - Server.MapPath 在当前上下文中不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19195663/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com