Search code examples
asp.neturlweb-applicationsrepeater

Folder name appended in URL


I am building an ASP.NET/VB web application. In my Main.Master page, I am using a Repeater control for my category (navigation) menu. It is pulling the data out of my Category table using an SQLDataSource control. The Item Template for the Repeater is this:

<ItemTemplate>
     <div class="category_item">
        <li>
          <a href='ProductsList.aspx?CategoryId=<%#Eval("category_id")%>'><%#Eval("category_name")%></a>
        </li>
      </div>
</ItemTemplate>

Now for the issue:

In my project structure, I have created a folder called Administration that holds the administrator-related pages, and also a folder called Account. If I navigate to a page in ANY of those folder (I assume it will happen to any folders I create), and THEN try to use my Repeater to navigate elsewhere, the folder name is appended in the URL path as follows:

Before:

http://localhost:xxxx/ProductsList.aspx?CategoryId=3

After: (assuming I logged-in and visited a page in one of those folders)

http://localhost:xxxx/Administration/ProductsList.aspx?CategoryId=3

What might be causing this?


Solution

  • When an application runs, it stores a "default" folder path on the disk - this is usually the folder where the executable (.exe) file is stored. If your code uses functions to change that location (like Directory.SetCurrentDirectory()) to get into your sub-folder, it will change that "default" folder setting.

    If the links on your navigation page don't specify the full path to a page like you just put "NextPage.asp" in the link instead of "E:\folder\NextPage.asp" then when the application gets the "fullpath" to the file it will pre-pend the default folder path to the URL when trying to find the file.

    An easy way to fix this is to simply put the full URL path to each page in the navigation URLs like your first URL:

    http://localhost:xxxx/ProductsList.aspx?CategoryId=3