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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:29:31+00:00 2026-05-18T12:29:31+00:00

So, ASP.net has the concept of an ‘application root’. It is the path part

  • 0

So, ASP.net has the concept of an ‘application root’. It is the path part of the URL that corresponds to the root directory that is set for an application in IIS. The tilde character (~) maps to that path in ASP.net URLs, so if ASP.net thinks my application is at /MyApp, something in a server control whose URL I give as “~/Scripts/script.js” will resolve to (and be sent to the browser as) “/MyApp/Scripts/script.js”.

This is a long shot, but is there a way I can change this application root arbitrarily? I actually have an app in a directory under another one and I’m using URL rewriting to make it available without prefixing the directory name, but ASP.net is always prefixing the dir name anyway anywhere I use ~. I really want to make ~ resolve to an empty string. Can one 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-05-18T12:29:31+00:00Added an answer on May 18, 2026 at 12:29 pm

    You should be able to change the semantic of what ~ maps to by writing a custom VirtualPathProvider. Here is what it might look like. I have tested this on a simple case, but it probably needs polishing.

    I suggest you play around with it an a simple test app before you move it to your real scenario. That’ll make it easier to isolate issues and iterate on it.

    using System;
    using System.Collections;
    using System.IO;
    using System.Linq;
    using System.Web;
    using System.Web.Caching;
    using System.Web.Hosting;
    
    public class TildeModifyingVPP : VirtualPathProvider {
    
        // Change this to what you want ~ to map to
        private const string PseudoRoot = "~/PseudoAppRoot/";
    
        public static void AppInitialize() {
            HostingEnvironment.RegisterVirtualPathProvider(new TildeModifyingVPP());
        }
    
        private string ResolvePath(string virtualPath) {
            // Make it app relative, i.e. ~/...
            virtualPath = VirtualPathUtility.ToAppRelative(virtualPath);
    
            // Change the ~/ to our pseudo root
            return PseudoRoot + virtualPath.Substring(2);
        }
    
        public override bool FileExists(string virtualPath) {
            return base.FileExists(ResolvePath(virtualPath));
        }
    
        public override VirtualFile GetFile(string virtualPath) {
            return new DelegatingVirtualFile(virtualPath, base.GetFile(ResolvePath(virtualPath)));
        }
    
        public override bool DirectoryExists(string virtualDir) {
            return base.DirectoryExists(ResolvePath(virtualDir));
        }
    
        public override VirtualDirectory GetDirectory(string virtualDir) {
            return new DelegatingVirtualDirectory(virtualDir, base.GetDirectory(ResolvePath(virtualDir)));
        }
    
        public override CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart) {
            virtualPathDependencies = virtualPathDependencies.Cast<string>().Select(vpath => ResolvePath(vpath));
            return base.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart);
        }
    }
    
    class DelegatingVirtualFile : VirtualFile {
        private VirtualFile _underlyingFile;
        public DelegatingVirtualFile(string virtualPath, VirtualFile underlyingFile): base(virtualPath) {
            _underlyingFile = underlyingFile;
        }
    
        public override Stream Open() {
            return _underlyingFile.Open();
        }
    }
    
    class DelegatingVirtualDirectory : VirtualDirectory {
        private VirtualDirectory _underlyingDir;
        public DelegatingVirtualDirectory(string virtualPath, VirtualDirectory underlyingDir)
            : base(virtualPath) {
            _underlyingDir = underlyingDir;
        }
    
        public override IEnumerable Children { get { return _underlyingDir.Children; } }
        public override IEnumerable Directories { get { return _underlyingDir.Directories; } }
        public override IEnumerable Files { get { return _underlyingDir.Files; } }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was in a ASP.NET application has heavy traffic of AJAX requests. Once a
I'm developing an intranet webapp in asp.net that has a requirement for storing user
I understand that ASP.NET WEB API has been built to help implement lightweight REST
ASP.Net has the concept of using 'subkeys' in cookies. i.e. You can write a
Asp.net WebForms and MVC has a concept of Masterpages which make it easy to
I have an ASP.NET MVC (using the release candidate) application that works with a
I wish to create an ASP.NET web application that allows upload of files up
Asp.net has an Application_End event which occurs when the application comes to end, like
Problem ASP.NET has no concept of associating permissions to roles. My app Current web
My gridview in asp.net has a column that shows currency in Euro format which

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.