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.
return AppDomain.CurrentDomain
.GetAssemblies()
.Any(
a => a.FullName.StartsWith("WebDev.WebHost")
);
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:
#if DEBUG
// Code compiled only if debug configuration selected (not release)
#endif
More info here
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
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.
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.
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