I want to know if the DLL is being used in web or desktop context. One way is to check if HttpContext
is null or not. But I want to know if there is other better way to do it.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
We went through the very same thing, as we have a .DLL that runs in both a Windows and a Web app and you've already nailed the way to determine which is which.
public bool IsWebApp()
{
return (HttpContext.Current != null);
}
Then within your application, you just query:
if ( this.IsWebApp() )
{
//do webby stuff...
}