如何确定.NET code是一个ASP.NET进程中运行? [英] How to determine if .NET code is running in an ASP.NET process?

查看:132
本文介绍了如何确定.NET code是一个ASP.NET进程中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有将两个下执行的通用类的实例 ASP.NET和一个独立的程序。这code是sensative的过程,其中它 是正在运行 - 即,有certin方法不应如果叫 ASP.NET下运行。你如何确定code正在执行一个ASP.NET 流程?

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 - that is, there are certin methods that should not called if running under ASP.NET. How do you determine if the code is executing in an ASP.NET process?

我目前使用的解决方案如下回答。

The solution I am currently using is answered below.


我希望有人能添加评论,为什么这个问题已经得到downvoted和/或提出一个更好的方式来问吧!我只能假设至少有一些人已经看过了这个问题,并说:什么样的白痴,ASP.NET code是.NET code。

I wish someone would add a comment as to why this question has gotten downvoted and/or propose a better way to ask it! I can only assume at least some folks have looked at the question and said "what an idiot, ASP.NET code is .NET code".

推荐答案

HttpContext.Current也可以在ASP.NET中为空,如果你使用的是异步方法,如异步任务发生在一个新的线程不共享原始线程的HttpContext的。这可能是也可能不是你想要的,但如果没有的话我相信HttpRuntime.AppDomainAppId将在ASP.NET处理非空的​​任何地方和其他地方空。

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.

这篇关于如何确定.NET code是一个ASP.NET进程中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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