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

  • Home
  • SEARCH
  • 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 8330523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:08:53+00:00 2026-06-09T02:08:53+00:00

My MVC3 Web Application is not always deployed as a site in IIS, so

  • 0

My MVC3 Web Application is not always deployed as a site in IIS, so I need to detect if it has been deployed as a virtual directory or application in order to handle the path string.

for example, if the site is deployed as a website under IIS root, if i write:

\ABC\test.txt

this is fine, the request goes to http://somehost/ABC/test.txt

but if the site is deployed as a virtual directory or application under an existing site in IIS, for example:

http://somehost/mymvcapp/

then, the request for “\ABC\test.txt” will not be correct.

I understand that write “~\App_Data\test.txt” will solve the problem, but “~\” can only be processed by the server in current web context. Sometime I need to do some process on the file in other layers, they can’t touch web context.

So I need to detect if the application has been deployed as a virtual directory. and find the actual physical path to the file. Is there any way to do it?

  • 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-09T02:08:54+00:00Added an answer on June 9, 2026 at 2:08 am

    If your business layer can’t reference System.Web, then you have to expect that it can’t detect any information about your web application period. This means that the code should not be expected to resolve file paths within your site.

    What you could do instead is have an intermediate configuration layer that the application initializes and the business layer can consume. For example, given this interface which is accessible to both layers:

    public interface IConfiguration
    {
        string DataFolder { get; }
    }
    

    … you could have code in your Global.asax that initializes it:

    IConfiguration config = ...;
    ...
    config.DataFolder = this.Server.MapPath("~/App_Data");
    

    Your business layer can now just read the configuration and form a path to the expected file:

    var filePath = Path.Combine(this.configuration.DataFolder, "test.txt");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I’m using authentication with Active Directory within an ASP .NET MVC3 web application. I
I have MVC3 web application running under IIS 7. During initialization in global.asax application
I've got an MVC3 web application that has a general search box and displays
Getting error inside MVC3 web application. LINQ to Entities does not recognize the method
in an ASP.NET MVC3 web application. I have a view. the view has a
I have been working on ASP.net MVC3 Web application using MSSQL 2008 R2 for
My new MVC3 web application allows users to store some information about themselves, and
i have created an mvc3 web application that uses forms based authentication. one part
I am building a new asp.net MVC3 web application for reporting and I want
I'm working on a ASP.NET MVC3 web application and I want to create a

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.