Know in what context DLL is running

扶醉桌前 提交于 2020-01-06 00:51:47

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!