服务器.MapPath()

发布于 2024-08-07 06:56:00 字数 254 浏览 4 评论 0原文

我想使用 Server.MapPath() 方法来映射虚拟目录 我创建了它的物理路径。

问题是 .net 环境无法识别 Server.MapPath()。

Google 告诉我我应该使用 System.Web 来使用 HttpContext.Current.Server, 但尽管我使用 System.Web,但 HttpContext 未被识别。 (我已经检查过 - HttpContext 是 System.Web 的类之一)

有帮助吗?

I want to use Server.MapPath() method im order to map a virtual directory
I created to its physical path.

The thing is that the .net environment doesn't recognize Server.MapPath().

Google told me I'm supposed to use HttpContext.Current.Server using System.Web,
but HttpContext isn't recognized in spite of me using System.Web. (And I've checked -
HttpContext IS one of System.Web's classes)

Help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

装迷糊 2024-08-14 06:56:00

确保您的项目中已包含 System.Web
执行这些操作(在 Visual Studio IDE 中):

  1. 右键单击​​项目节点(解决方案资源管理器窗口)
  2. 在上下文菜单上,单击“添加引用”
  3. 在 .NET 选项卡列表项上选择 System.Web。
  4. 点击“确定”按钮

Server.MapPath 现在应该可用。

Make sure you have included System.Web in your projects References
Do these (In Visual Studio IDE):

  1. Right click on the Project Node (Solution Explorer Window)
  2. On the context mennu, click Add Reference
  3. Select System.Web on the .NET Tab list items.
  4. Hit OK button

Server.MapPath should now be available.

傲世九天 2024-08-14 06:56:00

如果您有一个 Web 应用程序,您应该自动拥有对 System.Web.dll 的引用,并且您应该有权访问 System.Web.HttpContext 类。检查您是否意外删除了引用。您需要使用 using System.Web; 语句来访问 HttpContext 类,而不指定完整的命名空间。

如果您没有 Web 应用程序,则必须添加对 System.Web.dll 的引用才能访问 HttpContext 类,但这对您没有帮助一点。由于您不在 Web 应用程序中,因此没有 HTTP 上下文,也没有 Web 根文件夹,因此您无法使用 MapPath 方法。

If you have a web application, you should automatically have a reference to System.Web.dll, and you should have access to the System.Web.HttpContext class. Check that you haven't accidentally removed the reference. You would need a using System.Web; statement to access the HttpContext class without specifying the complete namespace.

If you don't have a web application you would have to add a referece to System.Web.dll to get access to the HttpContext class, but that would not help you a bit. As you are not in a web application, there is no HTTP context and there is no web root folder, so you can not use the MapPath method.

飞烟轻若梦 2024-08-14 06:56:00

这里同样的问题。在 ASP.net 4.0 Web 应用程序的 .ashx 处理程序中,顶部有 using System.Web。我无法使用 Server.MapPath() (这是我在书中所说的)或 System.Web.HttpServerUtility.MapPath() (这是 Google 和 MSDN 的内容)继续出现。我也无法使用上面提到的 HttpServerUtility.MapPath() 。

但是,这里的其他答案之一提示我尝试 context.Server.MapPath() ,它在我的 ProcessRequest(HttpContext context) 方法中起作用。

Same problem here. In an ASP.net 4.0 web application, in a .ashx handler, with a using System.Web at the top. I couldn't use Server.MapPath() which is what the book I have says to use or System.Web.HttpServerUtility.MapPath() which is what Google and MSDN keep turning up. I also couldn't use HttpServerUtility.MapPath() as mentioned above.

However, one of the other answers here prompted me to try context.Server.MapPath() which does work in my ProcessRequest(HttpContext context) method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文