如何确定 Cassini 是否正在运行您的 Web 应用程序?
基本上,标题中的问题 - 我/是否有可能确定 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
你可以看看端口。 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.
如果您的目标只是确定是否正在调试(在这种情况下,构建配置可能会进行调试),您可以使用类似以下内容的内容:
更多信息 此处
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:
More info here
以下内容表明您的应用程序正在 casini 下运行:
浏览器有一个端口提到
它(通常是一个很大的数字 - 大于 1000)
为 casini 服务器运行的进程
WebServer40.exe
The following suggest that your app is running under casini:
the browser has a port mentioned in
it (generally a high number - greater than 1000)
process running for casini server
WebServer40.exe
如果我理解正确,您想确定是否处于调试模式,并可能应用一些调试逻辑?
过去,我已经使用我在 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.
分析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.
虽然我喜欢这里的很多想法,但我认为我找到了一种简单的方法来实现这一目标。
这会给出一个布尔值,具体取决于是否存在附加到执行代码的调试器。
我仍然喜欢 vc 74 提供的
#if
代码,但是这个代码更符合我的目的。While I like a lot of the ideas here, I think I found a simple way to accomplish this.
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.