URL mapping – ASP.NET 2.0 New feature

URL mapping – ASP.NET 2.0 New feature

 

Defines a mapping that hides the real URL and maps it to a more user-friendly URL.

……

     <system.web>

         <urlMappings enabled="true">

              <add url="~/computerparts.aspx" mappedUrl="~/products/index.aspx?cid=01" />

              <add url="~/digitalcamera.aspx" mappedUrl="~/products/index.aspx?cid=02" />

              <add url="~/electronics.aspx" mappedUrl="~/products/index.aspx?cid=03" />

              <add url="~/laptop.aspx" mappedUrl="~/products/index.aspx?cid=04" />

              <add url="~/games.aspx" mappedUrl="~/products/index.aspx?cid=05" />

         </urlMappings>

     </system.web>

用户看到的是url,而mappedUrl特性描述了实际请求的页面。

***

You can add items to the urlMappings collection using the configuration API:

Code snippet:


Configuration config =

       WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);

UrlMappingsSection section =

       (UrlMappingsSection)config.GetSection("system.web/urlMappings");

section.UrlMappings.Add(new UrlMapping("~/video.aspx", "~/products/index.aspx?cid=08"));

config.Save();

 

You can iterate through your query, adding items to the collection.


posted @ 2006-12-23 20:43  Rickie  阅读(736)  评论(1编辑  收藏  举报