TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

ASP.NET UrlMappings Example: Redirects

This ASP.NET article shows how to use the UrlMappings element in Web.config.

UrlMappings. The urlMappings element redirects URLs to new locations.

This element is part of an ASP.NET config file. It redirects Googlebot and users alike to the new locations. It is easily added to Web.config to perform this complex task.

Example. We can use urlMappings, a special tag you can put in your Web.sitemap. Here is a table of some "old style" URLs that I want to map to new URLs. You can see the new URLs had SEO improvements with more keywords.

Examples for: url

~/Content/Page10.aspx
~/Content/Page13.aspx
~/Content/Page25.aspx

Examples for: mappedUrl

~/Content/Int-Parse-Conversion.aspx
~/Content/Post-Pre-Build-Macros.aspx
~/Content/Programming-Blogs.aspx

Example 2. You can add urlMappings by adding markup to Web.config. The "~" symbol, called a tilde, is a reference to the root of the virtual application directory. That is the root directory of your website. This example shows the urlMappings tag.

Web.config examples: XML

<urlMappings enabled="true">
    <add url="~/Content/Page22.aspx"
	mappedUrl="~/Content/ASP-TreeView-Recursion.aspx"/>
    <add url="~/Content/Page9.aspx"
	mappedUrl="~/Content/Directed-Acyclic-Word-Graph.aspx"/>
</urlMappings>

Open Web.config. This file is part of your website project in the Solution Explorer. You will need to double-click on it. Next, find the system.web element. Locate the <system.web> element and its closing tag.

Then: Put your <urlMappings> block into a section in the middle of that section.

 

Summary. We used urlMappings as a quick fix for redirecting requests on an ASP.NET server. There are other methods that may be more powerful. Use the RewritePath method in ASP.NET and Global.asax for a more flexible approach.


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf