知道在什么情况下DLL运行 [英] Know in what context DLL is running

查看:84
本文介绍了知道在什么情况下DLL运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如果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...
}

这篇关于知道在什么情况下DLL运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆