.net Determine at run time whether my app is an exe or a web app

我的梦境 提交于 2020-01-01 14:34:08

问题


I'm sure I have done this before in the past, but I've been in the docs for a bit, and can't seem to find it again. I need to be able to determine at run time in my business domain what context my application is running in. So that I may do some switching with config files, and use the proper method to determine if I am running in debug or release etc. I was pretty confident it was in System.Environment, but I have not come across it yet.


回答1:


Very easy method:

bool isWebApp = HttpContext.Current != null;

Works like a charm every time.




回答2:


I found the way I had done it earlier finally.

bool isWebApp = System.Web.HttpRuntime.AppDomainId != null;

It's much the same as Nathan's response though. Thanks for the reply.



来源:https://stackoverflow.com/questions/820595/net-determine-at-run-time-whether-my-app-is-an-exe-or-a-web-app

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