How to determine if Cassini is what's running your web app?

不想你离开。 提交于 2019-12-19 04:39:49

问题


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.


回答1:


return AppDomain.CurrentDomain
    .GetAssemblies()
    .Any(
        a => a.FullName.StartsWith("WebDev.WebHost")
    );



回答2:


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.




回答3:


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




回答4:


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



回答5:


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.




回答6:


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.




回答7:


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.



来源:https://stackoverflow.com/questions/4446728/how-to-determine-if-cassini-is-whats-running-your-web-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!