CodeMonkey1313
CodeMonkey1313

Reputation: 16031

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

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.

Upvotes: 1

Views: 633

Answers (7)

Andrew Davey
Andrew Davey

Reputation: 5451

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

Upvotes: 6

vc 74
vc 74

Reputation: 38179

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

Upvotes: 2

CodeMonkey1313
CodeMonkey1313

Reputation: 16031

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.

Upvotes: 0

Lex Li
Lex Li

Reputation: 63264

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.

Upvotes: 0

Keefu
Keefu

Reputation: 124

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.

Upvotes: 1

Mahesh Velaga
Mahesh Velaga

Reputation: 21971

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

Upvotes: 1

Samuel Neff
Samuel Neff

Reputation: 74939

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.

Upvotes: 2

Related Questions