How can a .NET code know whether it is running within a web server application?

前端 未结 7 1488
被撕碎了的回忆
被撕碎了的回忆 2020-12-06 02:49

I have a library code, which should be aware whether it is executed in the context of a web server or standalone application server.

The obvious that comes to mind i

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-06 03:29

    You can check for

    HttpContext.Current
    

    If it is not null then it is run from a web app.

    See HttpContext.Current Property

提交回复
热议问题