Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 27, 2012 03:20 AM by Dino He - MSFT
Member
11 Points
26 Posts
Apr 25, 2012 01:11 PM|LINK
Hi, I implemented Routing for URL Rewriting in my website but i'm getting errors. Please help to get out of these: Global.aspx Code:
<%@ Import Namespace="System.Web.Routing" %> <script runat="server"> void Application_Start(object sender, EventArgs e) { RegisterRoutes(); SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(SiteMap_SiteMapResolve); } private static void RegisterRoutes() { RouteTable.Routes.Add( "View Categories", new Route("{*CategoryName}", new CategoryRouteHandler()) ); }
Class1:
public static string FormatCategoryUrl(string categoryName) { return RouteTable.Routes.GetVirtualPath(null, "View Categories", new RouteValueDictionary { { "CategoryName", categoryName } }).VirtualPath; }
Class2:
public IHttpHandler GetHttpHandler(RequestContext requestContext) { string categoryName = requestContext.RouteData.Values["pro_cat_id"] as string; if (string.IsNullOrEmpty(categoryName)) return BuildManager.CreateInstanceFromVirtualPath("~/subcategory.aspx", typeof(Page)) as Page; else { HttpContext.Current.Items["Category"] = categoryName; return BuildManager.CreateInstanceFromVirtualPath("~/subcategory.aspx?pro_cat_id="+categoryName, typeof(Page)) as Page; } }
Page where category link is .aspx:
<asp:HyperLink ID="linkllname" runat="server" Text='<% #Eval("category") %>' NavigateUrl='<%# Helpers.FormatCategoryUrl(Eval("pro_cat_id").ToString()) %>'></asp:HyperLink>
Finally i want to get id/name in other page's aspx.cs file:like>>>
Request.QueryString["pro_cat_id"];So please tell me how to get this id /name like querystring in this page...Thanks in advance,Suraj Joshi.
Star
8068 Points
1023 Posts
Microsoft
Apr 27, 2012 03:20 AM|LINK
Hi
In .net 3.5 sp1, you can use
RouteCollection to your programe.
Here is the code example:
http://code.msdn.microsoft.com/Embed-language-code-in-URL-9d79559b
Hope it helpful.
surajjoshi13
Member
11 Points
26 Posts
Routing in asp.NET 3.5 sp1
Apr 25, 2012 01:11 PM|LINK
Hi,
I implemented Routing for URL Rewriting in my website but i'm getting errors. Please help to get out of these:
Global.aspx Code:
<%@ Import Namespace="System.Web.Routing" %> <script runat="server"> void Application_Start(object sender, EventArgs e) { RegisterRoutes(); SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(SiteMap_SiteMapResolve); } private static void RegisterRoutes() { RouteTable.Routes.Add( "View Categories", new Route("{*CategoryName}", new CategoryRouteHandler()) ); }Class1:
public static string FormatCategoryUrl(string categoryName) { return RouteTable.Routes.GetVirtualPath(null, "View Categories", new RouteValueDictionary { { "CategoryName", categoryName } }).VirtualPath; }Class2:
public IHttpHandler GetHttpHandler(RequestContext requestContext) { string categoryName = requestContext.RouteData.Values["pro_cat_id"] as string; if (string.IsNullOrEmpty(categoryName)) return BuildManager.CreateInstanceFromVirtualPath("~/subcategory.aspx", typeof(Page)) as Page; else { HttpContext.Current.Items["Category"] = categoryName; return BuildManager.CreateInstanceFromVirtualPath("~/subcategory.aspx?pro_cat_id="+categoryName, typeof(Page)) as Page; } }Page where category link is .aspx:
<asp:HyperLink ID="linkllname" runat="server" Text='<% #Eval("category") %>' NavigateUrl='<%# Helpers.FormatCategoryUrl(Eval("pro_cat_id").ToString()) %>'></asp:HyperLink>Finally i want to get id/name in other page's aspx.cs file:
like>>>
Dino He - MS...
Star
8068 Points
1023 Posts
Microsoft
Re: Routing in asp.NET 3.5 sp1
Apr 27, 2012 03:20 AM|LINK
Hi
In .net 3.5 sp1, you can use
RouteCollection to your programe.
Here is the code example:
http://code.msdn.microsoft.com/Embed-language-code-in-URL-9d79559b
Hope it helpful.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework