ASP.NET MVC4 “BIN” a reserved keyword?

I have a stock query application that returns data based upon a stock symbol.

Basically, the AJAX call goes to ~/Stocks/GetStockData/{id} where the {id} is the stock symbol.

This works fine… generally. Today I found that the stock “Progressive Waste Solutions Ltd.”, which has a symbol of BIN, blew up. Looking at the return data in the browser, I see it’s returning a 404 for this symbol.

It occurred to me that BIN might be a reserved word, asking for some binary file or something. Is this the case? How do I work around this without a whole lot of effort? Are there other keywords that will also cause this problem?

UPDATE

Per Artyom Neustroev, this could be a reserved keyword, and would be protected from routing to. He referenced an article which referenced a website which stated the way around this was to add the following configuration setting in the config file:

<configuration>
  <system.web>
    <httpRuntime relaxedUrlToFileSystemMapping="true"/>

    <!-- ... your other settings ... -->
  </system.web>
</configuration>

 

The routing mechanism takes into account hidden directories and files (like web.config, /bin, etc) and hides them from people. For some of these, the rules can be relaxed a bit, as they are handled in code. These “keywords” are: CON, COM1, COM2, COM3, COM4, LPT1, LPT2, AUX, PRN, and NUL. These can actually be referenced with a change to your web.config file as such:

<configuration>
  <system.web>
    <httpRuntime relaxedUrlToFileSystemMapping="true"/>

    <!-- ... your other settings ... -->
  </system.web>
</configuration>

How to add leading zeros to a number

I saw the question “How to add leading zeros to a number” on the ASP.NET forums countless times before. And often the answers provide solutions that work, but are overkill as well.

The two cleanest methods I know are String.Format and PadLeft.

   1:  Console.WriteLine("Using .ToString()");
   2:  Console.WriteLine(String.Format("{0:0000}", 16));
   3:   
   4:  Console.WriteLine("-------------------");
   5:   
   6:  Console.WriteLine("Using .PadLeft()");
   7:  Console.WriteLine(Convert.ToString(16).PadLeft(4, '0'));

You can see the result here.

//Using .ToString()
//0016
//-------------------
//Using .PadLeft()
//0016