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

☆樱花仙子☆ 提交于 2019-12-01 02:03:48
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.

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