我如何确定,如果执行的程序集是一个Web应用程序或WinForm的/控制台? [英] How do I determine if the executing assembly is a web app or winform/console?
本文介绍了我如何确定,如果执行的程序集是一个Web应用程序或WinForm的/控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编写一个辅助功能,建立异常信息写入日志。 在code样子:
I would like to write a helper function which build the exception message to write to a log. The code look like:
如果(IsWebApp)
{
     使用的HttpContext获取请求路径和RawUrl
}
其他
{
      //否则一个WinForm /控制台
     使用汇编得到执行路径。
}
if(IsWebApp)
{
use HttpContext to get the Request Path and RawUrl
}
else
{
//else it a winform/console
Use Assembly to get executing path.
}
推荐答案
使用的httpRuntime 类:
if (!String.IsNullOrEmpty(HttpRuntime.AppDomainAppVirtualPath))
//ASP.Net
else
//Non-ASP.Net
这篇关于我如何确定,如果执行的程序集是一个Web应用程序或WinForm的/控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文