我如何确定,如果执行的程序集是一个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