如何确定 Cassini 是否正在运行您的 Web 应用程序?

发布于 2024-10-07 20:02:11 字数 97 浏览 0 评论 0原文

基本上,标题中的问题 - 我/是否有可能确定 Cassini 是运行我的应用程序而不是 IIS?基本上我希望我的代码知道它正在调试,所以如果我在这里遗漏了一些更简单的东西,请指出。

Basically, the question in the title - how can I / is it possible to determine that Cassini is what's running my app versus IIS? Basically I want my code to know that it's debugging, so if I'm missing something easier here, please point it out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

时光倒影 2024-10-14 20:02:11
return AppDomain.CurrentDomain
    .GetAssemblies()
    .Any(
        a => a.FullName.StartsWith("WebDev.WebHost")
    );
return AppDomain.CurrentDomain
    .GetAssemblies()
    .Any(
        a => a.FullName.StartsWith("WebDev.WebHost")
    );
幸福丶如此 2024-10-14 20:02:11

你可以看看端口。 Casini 始终在随机高端口上运行。除非您进行了不同的配置,否则 IIS 通常为 80 或 443。

You can look at the port. Casini always runs on a random high port. IIS will usually be 80 or 443 unless you've configured it differently.

一紙繁鸢 2024-10-14 20:02:11

如果您的目标只是确定是否正在调试(在这种情况下,构建配置可能会进行调试),您可以使用类似以下内容的内容:

#if DEBUG
    // Code compiled only if debug configuration selected (not release)
#endif

更多信息 此处

If your goal is solely to determine whether you are debugging (in which case the build configuration will probably be debug), you can use something like:

#if DEBUG
    // Code compiled only if debug configuration selected (not release)
#endif

More info here

妄想挽回 2024-10-14 20:02:11

以下内容表明您的应用程序正在 casini 下运行:

  • 当您运行您的应用程序时,如果您的 URL 在
    浏览器有一个端口提到
    它(通常是一个很大的数字 - 大于 1000)
  • 您可以检查您的项目属性(Web 选项卡)以检查它是否在 IIS 或 Web 开发服务器(casini)下运行,
  • 将会有一个
    为 casini 服务器运行的进程
    WebServer40.exe

The following suggest that your app is running under casini:

  • When you run your app, if your URL in
    the browser has a port mentioned in
    it (generally a high number - greater than 1000)
  • You can check your project properties (Web tab) to check if it is running under IIS or Web Development server (casini)
  • There will be a
    process running for casini server
    WebServer40.exe
太阳公公是暖光 2024-10-14 20:02:11

如果我理解正确,您想确定是否处于调试模式,并可能应用一些调试逻辑?

过去,我已经使用我在 web.config 中添加的密钥完成了您尝试实现的目标。当我开发和调试时,我设置变量 RunningFromVisualStudio=true,当我升级到生产时,我将变量设置为 false。

希望有帮助。

If I am understanding you correctly, you want to determine if you are in debug mode or not and perhaps apply some debugging logic?

In the past, I have accomplished what you are attempting to achieve using a key that I added in the web.config. When I am developing and debugging, I set the variable RunningFromVisualStudio=true and when I promote to production, I set it the variable to false.

Hope that helps.

单调的奢华 2024-10-14 20:02:11

分析HTTP响应,看看Server字段是什么。这应该说的是实话。 IIS默认会告诉它是IIS(带有版本号)。

Analyze the HTTP response and see what is the Server field. That should tell the truth. IIS will tell it is IIS (with version number) by default.

寻找一个思念的角度 2024-10-14 20:02:11

虽然我喜欢这里的很多想法,但我认为我找到了一种简单的方法来实现这一目标。

System.Diagnostics.Debugger.IsAttached

这会给出一个布尔值,具体取决于是否存在附加到执行代码的调试器。

我仍然喜欢 vc 74 提供的 #if 代码,但是这个代码更符合我的目的。

While I like a lot of the ideas here, I think I found a simple way to accomplish this.

System.Diagnostics.Debugger.IsAttached

This gives a boolean depending on whether there's a debugger attached to the executing code.

I still like the #if code provided by vc 74, but this code serves my purpose better.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文