开发者

System.Web.UI not giving me the MapPath

开发者 https://www.devze.com 2022-12-20 00:33 出处:网络
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

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.


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.


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 is in the System.Web namespace:

http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消