我试图重写我的网址,当我进行搜索。但我不能连得细分出我的网址,或者没有段但我不knwo如何去改变它。
我如何努力获得细分 Find.aspx 页面加载:
的IList<串GT;段= Request.GetFriendlyUrlSegments(); 的for(int i = 0; I< segments.Count;我++) { Label1.Text + = - +区段[I] + - ; }这是只是为了测试如果它甚至找到1段,它没有。
我自己也尝试在这我RouteConfig设置是这样的:
公共静态无效的RegisterRoutes(RouteCollection路线){ VAR设置=新FriendlyUrlSettings(); settings.AutoRedirectMode = RedirectMode.Permanent; routes.EnableFriendlyUrls(设置); routes.MapPageRoute(,查找,〜/ Find.aspx); routes.MapPageRoute(查找,查找/ {}的结果,〜/ Find.aspx);}我要的网址从:
www.site/Find?Result=Test要这样:
www.site/Find/Test或
www.site/Test我呼像这样的链接的Response.Redirect(〜/ Find.aspx?结果=+搜索字符串)
我也想知道如果本地主机:XXXXX /默认意味着,当我最终买了我的域名起始页看起来像 www.sitename /默认?如果是的话我怎么能重新路由是公正 www.sitename ?
基本上只是想使我的网站更SEO。
解决方案您需要以下行发表评论,那么它应该工作。
routes.MapPageRoute(,查找,〜/ Find.aspx);routes.MapPageRoute(查找,查找/ {}的结果,〜/ Find.aspx);更多信息 - 的转寄此。
这些行的目的用法 - 提供搜索引擎友好的名称 Find.aspx 。要使用此,你需要点击URL - 的http://本地主机:63197 /的findxxx
用法 - URL - 的http://本地主机:63197 / FindMore / ABC 。为了获得价值 - 你需要使用下面的 - Page.RouteData.Values [结果]
为什么它不工作 - 在你的情况,这两条线有搜索引擎友好的名称查找,这让混乱的路由引擎,然后失败。
如何制定以下是网址,我都试过了。
以下是输出,
和我有评论如下。
I am trying to rewrite my URLs when I make a search. But I can't even get the segments out of my URL, or maybe there are no segments but then I dont knwo how to change it.
How I try to get segments in Find.aspx pageload:
IList <string> segments = Request.GetFriendlyUrlSegments(); for (int i = 0; i < segments.Count; i++) { Label1.Text += "- " + segments[i] + " -"; }This is just to test if it even find 1 segment, which it does not.
I have also tried setting in it my RouteConfig like this:
public static void RegisterRoutes(RouteCollection routes) { var settings = new FriendlyUrlSettings(); settings.AutoRedirectMode = RedirectMode.Permanent; routes.EnableFriendlyUrls(settings); routes.MapPageRoute("", "Find", "~/Find.aspx"); routes.MapPageRoute("Find", "Find/{Result}", "~/Find.aspx"); }I want to change the URL from this:
www.site/Find?Result=TestTo this:
www.site/Find/Testor
www.site/TestI "call" the link like this Response.redirect("~/Find.aspx?Result=" + searchString)
I am also wondering if Localhost:xxxxx/Default Means that when I eventually buy a domain my startpage will look like www.sitename/Default? If so how can I reroute that to be just www.sitename?
Basically just want to make my site more SEO.
解决方案You need to comment below lines, then it should work.
routes.MapPageRoute("", "Find", "~/Find.aspx"); routes.MapPageRoute("Find", "Find/{Result}", "~/Find.aspx");More info -- Refer this.
Purpose of these linesUsage - It provides SEO friendly name to Find.aspx. To use this, you need to hit url - localhost:63197/FindXXX
Usage - URL - localhost:63197/FindMore/abc. To get value - you need to use following - Page.RouteData.Values["Result"]
Why it was not working - In your case, both lines had SEO friendly name as Find and that made confusion to routing engine, and then failed.
How workedFollowing is the url, I have tried.
Following is the output,
And I have commented following.
更多推荐
重新路由使用friendlyUrl查询字符串
发布评论