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 7696505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:47:40+00:00 2026-05-31T21:47:40+00:00

In my library I use HostingEnvironment.MapPath for my web application. But I need to

  • 0

In my library I use HostingEnvironment.MapPath for my web application. But I need to call the same function from a windows forms and a windows service.

In Windows application HostingEnvironment.ApplicationID is null, in Web application HostingEnvironment.ApplicationID is something like “99xxx999”.

Can I use “HostingEnvironment” to determine if it is Web or Win?

Is it safe to use this?

if (HostingEnvironment.ApplicationID == null)
{
    //called from windows application
}
else
{
    //called from web application
}
  • 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-05-31T21:47:41+00:00Added an answer on May 31, 2026 at 9:47 pm

    A more standard way to do this it to use the HttpContext.Current method:

    if (HttpContext.Current == null)
    {
        // called from windows application
    }
    else
    {
        // called from web application
    }
    

    Of course using HttpContext related stuff in non-HTTP related layers of your application is a design smell. It not only smells => it stinks.

    A more standard way is to have your code be passed as argument directly the filename as argument. When called from within a web application you would pass Server.MapPath("~/foo.txt") and when you call it from within a Windows Application you would directly pass the file name relative to the current executable.

    This way your code doesn’t need to depend on any HTTP specific stuff and can be happily reused in any platform. It is the responsibility of the caller to pass it the filename that your code needs to process. The way this filename is determined is platform specific. Not your code responsibility. Don’t mix responsibilities.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What library should I use to connect to odbc from python on windows? Is
I use SharpSvn library from CollabNET. I would like to set revision author while
Is it possible to use a library compiled by visual studio in an application
I use library which download torrents. But today some error happened (log): Could not
I need a easy to use library whit examples for converting NSObjects to JSON
I'm creating a library for use with an application that I am building. I
What the best library to use for mock, stub... in ROR application?
I am writing a generic library for use by all of my web projects.
Which Java PDF library to use in commercial project? I need to generate a
Can anyone recommend a decent SFTP library for use with Windows C++ apps? If

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.