System.Web.UI 没有给我 MapPath
我正在研究 mailSender 类。我无法使用 System.Web.UI 命名空间中的 Server.MapPath 方法。我应该设置什么参考来完成这项工作?我已经引用了System/System.Web/System.Web.UI。
I am working on a mailSender Class. I can't use the Server.MapPath method from the System.Web.UI Namespace. What reference should i set to make this work? I have referenced to the System / System.Web / System.Web.UI.
This is the msdn i have checked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请阅读本页上的 TaylorMichaelL 答案: 名称“服务器”在当前上下文中不存在。这应该对你有帮助。
不过,更好的方法是将目标文件夹添加为方法参数并从中创建路径。这样,该类也可以在非 Web 环境中使用。
Please read TaylorMichaelL answer on this page: The name 'Server' does not exist in the current context. This should help you.
A better approach though is that you add the target folder as a method argument and create the path from that. That way, the class will be usable in non-web contexts as well.
对于遇到此问题的人,我将回答我自己的问题,这样他们就不必点击其他网站的链接。
如果您想使用 Server.Mappath,则在使用 DAL 或 BL 时将无法执行此操作。
您可以使用 HttpContext.Current 属性来访问这些对象(假设它们在上下文中可用)。该属性为您提供当前上下文。 但是,您现在正在尝试将 DAL/BL 连接到 ASP.NET。
因此,您可以解决此问题的方法是将 Server.Mappath 放在与上下文相关的位置,例如在您的代码隐藏中。
GL!
For people that will encounter this problem i will answer my own question so they don't have to follow links to other websites.
If you want to use the Server.Mappath, you won't be able to do this when using a DAL or BL.
You can gain access to these objects (assuming they are available at the time given that they are contextual) by using the HttpContext.Current property. This property gives you the current context. However you are now trying your DAL/BL to ASP.NET.
So what you could do to fix this issue is getting the Server.Mappath on a place where it is contextual, like in your Code Behind.
GL!
Server.MapPath 位于 System.Web 命名空间中:
http ://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx
Server.MapPath is in the System.Web namespace:
http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx