我想知道如果DLL在Web或桌面环境使用。一种方法是检查的HttpContext
为空或不是。但我想知道是否有其他更好的方式来做到这一点。
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.
我们通过同样的事情去了,因为我们有一个运行在既有的Windows和Web应用一个.DLL,你已经钉的方式确定哪个是哪个
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...
}