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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:04:08+00:00 2026-06-05T11:04:08+00:00

I am trying to gain some insight into what causes a particularly odd error

  • 0

I am trying to gain some insight into what causes a particularly odd error I have been seeing. I have isolated the issue as follows:

Create an ASP.Net MVC application with a two basic controllers.

public class HasLocationController : Controller
{
   public ActionResult Index()
   {
      return View();
   }
}

public class NoLocationController : Controller
{
   public ActionResult Index()
   {
      return View();
   }
}

Add a location element to the web.config for the path ‘HasLocation’

<location path="HasLocation">
   <system.web>
      <authorization>
         <allow users="*"/>
      </authorization>
   </system.web>
</location>

Publish the site to IIS6 or IIS7 (IISExpress and WebDevServer won’t work), and attempt to browse using the following links:

http://[yourdomain]/NoLocation/%20~C:/blah.txt

http://[yourdomain]/HasLocation/%20~C:/blah.txt

For the controller that has no corresponding location element configured, you get the kind of exception message you would expect.


Exception From Controller Without Location Element


However, if you attempt the same thing on the controller with the location element, then you get this strange error:

NOTE: This only happens with the leading tilde (~) character. Without that, you get the normal error you would expect.


Error When Using Location Element


I haven’t been able to really find documentation regarding this error, but I am very interested to understand why this is happening, and how to prevent it.

ANY light you could shed on the issue would be helpful.

  • 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-05T11:04:09+00:00Added an answer on June 5, 2026 at 11:04 am

    There are virtually hundreds of answers on the internet regarding this error. Most likely it has nothing to do at all with your controllers but with:

    ~C:/blah.txt

    Specifically the : Which it probably finds as being potentially dangerous. Take a look at HttpRuntimeSection.RequestPathInvalidCharacters.

    As for the second error. It is correct, the directory HasLocation does not exist in your project. When it is created, you will get the first error. When you remove the : it will attempt to load whatever file you requestion in the HasLocation directory.

    NOTE: You MUST NOT use the location element in the web.config to security MVC application controllers, you need to use the AuthorizeAttribute or other custom attributes like it.

    Here is a Reference and any search of SO or Google will pretty much say the same thing:

    You cannot use routing or web.config files to secure your MVC application. The only supported way to secure your MVC application is to use a base class with an [Authorize] attribute, and then have each controller type subclass that base type.

    Restate of whats happening:

    First Error: Your URL is throwing an error due to the HttpRuntimeSection.RequestPathInvalidCharacters.

    Second Error: It doesn’t matter if you have controllers or not. The default ASP.Net Webforms engine is trying to detect if a directory exists as you specified in the url (in your case a directory called HasDirectory) because it needs to authorize the directory access for the Webforms engine as you specified in the web.config location element. It’s not even worried about the file yet. Since this directory doesn’t exist, you get the error exactly as your image states (I’ve highlighted in green):

    Highlighted Error

    If you create the directory, then you get error #1.

    The entire ASP.Net runtime does something like this:

    1. Parse the Path necessary for the request.
    2. Validate any Authorization to the directory if it exists in the web.config location element.
    3. If it has access, get the file and parse it for whatever it is (aspx, etc)
    4. If the it doesn’t have access AND the file exists throw an exception or redirect as configured.
    5. If the file does NOT exist, ignore the location element in web.config and run the IIS catch all to determine if there is another route for the request.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to gain a deeper understanding of how compilers generate machine code,
I am trying to execute some queries using YQL. To gain some efficiency, I
I am a newbie in assembly and still trying to gain some basic foundation
I'm trying to gain some memory saving in a C++ program and I want
I'm a PHP developer who's trying to gain some proficiency in Ruby. One of
I'm trying to gain a basic understanding of what is meant by a Windows
I'm fairly new to Rails and I'm trying to gain a better understanding of
Trying to install py-bcrypt on win7. Python is 64bit. First error unable to find
Trying to convert a perl script to php. In perl I have a hash
I'm trying to write a quick app to modify some registry keys. When 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.