How do I determine if the executing assembly is a web app or winform/console?

后端 未结 5 1687
灰色年华
灰色年华 2021-01-18 02:14

I would like to write a helper function which build the exception message to write to a log. The code look like:

if(IsWebApp)
{

    &

5条回答
  •  独厮守ぢ
    2021-01-18 02:56

    I use the DomainManager type of Current AppDomain. MSDN documentation of AppDomainManager

    public static class AspContext
    {
        public static bool IsAspNet()
        {
            var appDomainManager = AppDomain.CurrentDomain.DomainManager;
            return appDomainManager != null && appDomainManager.GetType().Name.Contains("AspNetAppDomainManager");
        }
    }
    

    You can also check this other answer on SO

提交回复
热议问题