怎么在一个项目中判断,当前应用是B/S(web)还是C/S(win form)形式?

来源:百度知道 编辑:UC知道 时间:2024/07/05 20:30:13
建立一个公共类库,有可能应用在 web中也有可能应用在 win form中,怎么在程序里判断是当前应用是web还是winform呢?

写一个Helper方法去实现

static bool CheckWhetherIsWeb()
{
bool result = false;
var domain = AppDomain.CurrentDomain;
try
{
if (domain.ShadowCopyFiles)
result = (HttpContext.Current.GetType() != null);
}
catch (System.Exception) { }
return result;
}