Know in what context DLL is running

2019-08-12 20:49发布

问题:

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...
}


标签: c# .net dll