How to determine if .NET code is running in an ASP.NET process?

后端 未结 6 1702
一生所求
一生所求 2020-12-17 15:19

I have an instance of a general purpose class that will be executed both under ASP.NET and a stand alone program. This code is sensative to the process where it is being run

6条回答
  •  萌比男神i
    2020-12-17 15:25

    HttpContext.Current can also be null within ASP.NET if you're using asynchronous methods, as the asynchronous task happens in a new thread that doesn't share the HttpContext of the original thread. This may or may not be what you want, but if not then I believe that HttpRuntime.AppDomainAppId will be non-null anywhere in an ASP.NET process and null elsewhere.

提交回复
热议问题