This tutorial will show you how to use URL mapping technology in ASP.NET 2.0 and C#.
The URL mapping feature uses configuration information stored in web.config to remap incoming requests to a different URL. The remapping occurs prior to any other processing for the inbound request. Although the sample below demonstrates remapping a page request, any arbitrary file type can have its request remapped to a different URL.
At first you need to build a sitemap file Web.sitemap. The code as following:
| <?xml version="1.0" encoding="utf-8" ?> <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0"> <siteMapNode url="~/UrlMappingCsharp.aspx" title="Home Page" description="This is the home page" > </siteMap> <siteMapNode url="~/Category.aspx" title="Categories" description="Information Categories" > </siteMapNode><siteMapNode title="News" description="News" url="~/News.aspx" /> </siteMapNode><siteMapNode title="Games" description="Games" url="~/Games.aspx" /> <siteMapNode title="Health" description="Health" url="~/Health.aspx" /> |
Try Server Intellect for Windows Server Hosting. Quality and Quantity!
Secondly, please build a web.config file. The code is as following::| <?xml version="1.0" ?> <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> <system.web> </configuration> <urlMappings enabled="true"> </system.web><add </urlMappings>url="~/News.aspx" mappedUrl="~/UrlMappingVB.aspx?category=news" /> <add url="~/Category.aspx" mappedUrl="~/UrlMappingVB.aspx?category=default" /> <add url="~/Games.aspx" mappedUrl="~/UrlMappingVB.aspx?category=games" /> <add url="~/Health.aspx" mappedUrl="~/UrlMappingVB.aspx?category=health" /> |
Need help with Windows Dedicated Hosting? Try Server Intellect. I'm a happy customer!
The front end UrlMappingCsharp.aspx page looks something like this:| <table> <tr> </table> <td><asp:SiteMapDataSource Runat=server ID="SiteMapDataSource1" /> </tr> <br /></td> <tr> <td> </tr><asp:Label Runat=server Text="TreeView" id="Label3" ForeColor="#ff3366" /> <asp:TreeView ID="TreeView1" DataSourceID="SiteMapDataSource1" Runat=Server /> </td> <tr> <td> </tr> The current virtual path for the request is:<b> <% Response.Write(Request.Path)%></b>. <br /> The value of the category querystring variable is:<b> <% Response.Write(Server.HtmlEncode(Request.QueryString("category")))%></b>. <br /> However, the original path that was requested before it was remapped is:<b> <% Response.Write(Request.RawUrl)%></b>. </td> |
No comments:
Post a Comment