重新路由使用friendlyUrl查询字符串

编程入门 行业动态 更新时间:2024-10-27 20:30:39
本文介绍了重新路由使用friendlyUrl查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图重写我的网址,当我进行搜索。但我不能连得细分出我的网址,或者没有段但我不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);

更多信息 - 的转寄此。

这些行的目的
  • routes.MapPageRoute(,的findxxx,〜/ Find.aspx); 是替换 Find.aspx 用的findxxx,这里的findxxx 是搜索引擎友好的名称。而且它不会任何参数发送到 Find.aspx 。
  • 用法 - 提供搜索引擎友好的名称 Find.aspx 。要使用此,你需要点击URL - 的http://本地主机:63197 /的findxxx

  • routes.MapPageRoute(查找,FindMore / {}的结果,〜/ Find.aspx); - 此行添加SEO friendlyness +提供的方式来传递参数给搜索引擎友好的URL。
  • 用法 - 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=Test

    To this:

    www.site/Find/Test

    or

    www.site/Test

    I "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 lines

  • routes.MapPageRoute("", "FindXXX", "~/Find.aspx"); is to replace Find.aspx with FindXXX, here FindXXX is SEO friendly name. And it does not send any parameter to Find.aspx .
  • Usage - It provides SEO friendly name to Find.aspx. To use this, you need to hit url - localhost:63197/FindXXX

  • routes.MapPageRoute("Find", "FindMore/{Result}", "~/Find.aspx"); -- This line add SEO friendlyness + provides way to pass param to SEO friendly URL.
  • 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 worked

    Following is the url, I have tried.

    Following is the output,

    And I have commented following.

    更多推荐

    重新路由使用friendlyUrl查询字符串

    本文发布于:2023-11-13 01:20:24,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1583014.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:路由   字符串   friendlyUrl

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!