Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7816069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:44:05+00:00 2026-06-02T05:44:05+00:00

My C# code may be running inside an MVC3 application under IIS (currently 7.5,

  • 0

My C# code may be running inside an MVC3 application under IIS (currently 7.5, but I’d like to not depend on a specific version) or elsewhere.

Looks like one way to know that code is running under IIS is to check the current process name, but this approach depends on having a filename string hardcoded.

Is there some programmatic way to detect my code is running under IIS not depending on IIS version?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:44:07+00:00Added an answer on June 2, 2026 at 5:44 am

    Have a look at the HostingEnvironment class, especially the IsHosted method.

    This will tell you if you are being hosted in an ApplicationManager, which will tell you if you are being hosted by ASP.NET.

    Strictly, it will not tell you that you are running under IIS but I think this actually meets your needs better.

    Example code:

    // Returns the file-system path for a given path.
    public static string GetMappedPath(string path)
    {
        if (HostingEnvironment.IsHosted)
        {
            if (!Path.IsPathRooted(path))
            {
                // We are about to call MapPath, so need to ensure that 
                // we do not pass an absolute path.
                // 
                // We use HostingEnvironment.MapPath, rather than 
                // Server.MapPath, to allow this method to be used
                // in application startup. Server.MapPath calls 
                // HostingEnvironment.MapPath internally.
                return HostingEnvironment.MapPath(path);
            }
            else {
                return path;
            }
        }
        else 
        {
            throw new ApplicationException (
                    "I'm not in an ASP.NET hosted environment :-(");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I may be missing something obvious here, but how could I rewrite this code
Title may be confusing, but here's explanation with code. Based on some conditions, I
When i run this code the paintComponent method is not being called It may
Where can I find documentation on running JavaScript code inside a PDF? I've never
I'm new to Wicket and would like to maintain a web application from inside
This may be impossible, but I'm trying to save the state of my application
I am writing code for a C++ application foo.exe. Inside the application, I want
This one may seem like a simple question, but it's really got me scratching
Just after running my Delphi application i check for the installed MS Outlook version
I believe this code may require more effort to comprehend than average, so I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.