Search code examples
c#asp.netwebformswebaddress

Prevent subdirectory from being a part of the link?


I am currently refactoring my website and I noticed that my nested structure shows up like I'm browsing through File Explorer. I couldn't find anything on the web about preventing that from showing up that way.

I like to ensure my project is nice and organized and this results in pages that are sometimes up to 5 layers deep (basic example):

mywebsitedotcom/gaming/2d/arcade/pong.aspx

I would prefer this to look like:

mywebsitedotcom/gaming/pong.aspx

How do I ensure the web address doesn't display part of my organizational structure?


Solution

  • You could use something called UrlMapping.

    It is an element that goes in your web.config and it will similar to this:

    <system.web>
    
    <urlMappings enabled="true">
    
        <add url="~/gaming/2d/arcade/pong.aspx"
            mappedUrl="~/gaming/pong.aspx"/>
    
        <add url="~/anotherurl/another.aspx"
            mappedUrl="~/otherurl/otherpage.aspx"/>
    
    </urlMappings>