HttpContext.Current.Server空

编程入门 行业动态 更新时间:2024-10-24 01:58:05
本文介绍了HttpContext.Current.Server空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有使用方法,由一个类库用同样的asp解决方案Windows服务。在类库,我有以下行的方法:

I have a windows service which is using a method from a class library with same asp solution. in class library, I have a method with following line:

reader = XmlReader.Create(HttpContext.Current.Server .MapPath("~/TestDevice/Data.xml"), settings);

在控制谈到此行。我得到异常。我试着调试code和发现,当服务尝试然后访问该方法 HttpContext.Current.Server 是空。什么是替代语法。

When control comes to this line. I get exception. I tried to debug the code and found that when service tries to access this method then HttpContext.Current.Server is null. What is alternative syntax.

我试图来访问Web应用程序这个类库方法,它工作正常。

I tried to access this class library method from web application and it works fine.

请提出解决方案。

推荐答案

HttpContext.Current是返回null,因为您的Windows服务没有IIS的雨伞或一些其他的Web服务器provder下运行。

HttpContext.Current is returning null because your Windows Service is not running under the umbrella of IIS or some other web server provder.

然而,你可以使用反射找到你的服务的执行路径:

However, you can find the executing path of your service using reflection:

System.Reflection.Assembly.GetExecutingAssembly().Location

^应返回执行服务的路径。

^ should return the path of the executing service..

更多推荐

HttpContext.Current.Server空

本文发布于:2023-11-09 15:50:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572779.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:HttpContext   Current   Server

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!