Search code examples
asp.netvirtual-directory

How to detect if current site is in virtual directory


I have a website, which on DEV env. I use virtual directory, while in LIVE env. I don't. I want to distinguish between virtual directory & none virtual, in runtime.

How can I acheive this?

Thanks!


Solution

  • Go to the Web tab in Project Properties and change Virtual path to /.
    This will make the debugging server use the root.

    To answer the question, you're looking for the HttpRuntime.AppDomainAppVirtualPath, which gets the virtual path to the application root.