问题
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...
}
来源:https://stackoverflow.com/questions/4394740/know-in-what-context-dll-is-running