要显示的URL路由asp.net只查询字符串 [英] Want to show only query string in url routing asp.net

查看:83
本文介绍了要显示的URL路由asp.net只查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重写查询字符串的URL。下面是一个例子。

例如

www.test.com/user.aspx?Name=1234

我要重写像

www.test.com/1234

它与 www.test.com?Name=1234 工作的罚款 www.test.com/test/1234

我做它喜欢的:

 无效的Application_Start(对象发件人,EventArgs的发送)
{
    //上的应用程序启动时运行code
    RouteTable.Routes.MapPageRoute(StoreRoute
        {名称},
        〜/网页/测试/ Demo.aspx);
}


解决方案

如果我没有记错的话,你的问题是,你需要申请像www.test.com/1234的URL,而不是www.test.com/test / 1234。

这可以使用您在Global.asax文件中所提到的路线来完成。但这里的问题是,你必须直接使用一个单一的动态参数{}名称在定义您的路线。如果要定义一个单参数的任何其他途径,那么它将无法正常工作,说明如下:

  RouteTable.Routes.MapPageRoute(StoreRoute,{}名称,〜/网页/测试/ Demo.aspx);
RouteTable.Routes.MapPageRoute(StoreRoute1,{名称1},〜/网页/测试/ Demo1.aspx);

在上述情况下,第二路径将被宣告第一路径覆盖。

这是什么原因,最好给在路由声明静态参数。

  RouteTable.Routes.MapPageRoute(StoreRoute,测试/ {名},〜/网页/测试/ Demo.aspx);
RouteTable.Routes.MapPageRoute(StoreRoute1,测试1 / {名1},〜/网页/测试/ Demo1.aspx);

在后一种情况下,第二路径将不会被覆盖。

现在,如果你只需要定义一个路由,那么你的code会工作。

您可以在下面的链接查看我的URL路由博客系列。这个环节是我重发帖子。

http://karmic-development.blogspot.in/2013/10/url-routing-in-aspnet-web-forms-same.html

感谢和放大器;问候,
Munjal

I want to rewrite the URL with query string. Here is an example

e.g

www.test.com/user.aspx?Name=1234

I want to rewrite like

www.test.com/1234

It is working fine with www.test.com?Name=1234 to www.test.com/test/1234

I am doing it like:

void Application_Start(object sender, EventArgs e)
{
    // Code that runs on application startup
    RouteTable.Routes.MapPageRoute("StoreRoute",
        "{Name}",
        "~/Webpages/Test/Demo.aspx");
}

解决方案

If I am not mistaken, your problem is that you need to request a URL like www.test.com/1234 instead of www.test.com/test/1234.

This can be done using the route which you have mentioned in the global.asax file. But the issue here is that you have directly used a single dynamic parameter {Name} while defining your route. If you want to define any other route with a single parameter, then it will not work as explained below:

RouteTable.Routes.MapPageRoute("StoreRoute","{Name}","~/Webpages/Test/Demo.aspx");
RouteTable.Routes.MapPageRoute("StoreRoute1","{Name1}","~/Webpages/Test/Demo1.aspx");

In the above case, the second route will be overriden by the first route declared.

That is the reason, it's better to give a static parameter in the route declaration.

RouteTable.Routes.MapPageRoute("StoreRoute","test/{Name}","~/Webpages/Test/Demo.aspx");
RouteTable.Routes.MapPageRoute("StoreRoute1","test1/{Name1}","~/Webpages/Test/Demo1.aspx");

In the later case, the second route will not be overriden.

Now, if you only have to define a single route, then your code will work.

You can check my blog series on URL routing at below link. This link is of my resent post.

http://karmic-development.blogspot.in/2013/10/url-routing-in-aspnet-web-forms-same.html

Thanks & Regards, Munjal

这篇关于要显示的URL路由asp.net只查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆