asp.net c# 应用程序路由
我一直在尝试启动并运行一些路由。我基本上想要这个网址:
www.example.com/SomebodysName
或
www.example.com/agents/somebodysname
..去...
www.example.com/portfolio.aspx?ran=somebodysname
我尝试使用来自 MSDN 的示例,如下所示使用 globax.asax:
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(System.Web.Routing.RouteTable.Routes);
}
public static void RegisterRoutes(System.Web.Routing.RouteCollection routes)
{
routes.MapPageRoute("", "agents/{name}", "portfolio.aspx?ran={name}");
}
但我无法让它工作,它说命名空间 System.Web 中不存在路由。 我怎样才能让它以这种方式或另一种方式工作(web.config?)
I've been trying to get some routing up and running. I basically want this url:
www.example.com/SomebodysName
or
www.example.com/agents/somebodysname
..to go to...
www.example.com/portfolio.aspx?ran=somebodysname
I have tried to use an example from MSDN, using globax.asax like this:
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(System.Web.Routing.RouteTable.Routes);
}
public static void RegisterRoutes(System.Web.Routing.RouteCollection routes)
{
routes.MapPageRoute("", "agents/{name}", "portfolio.aspx?ran={name}");
}
but I can't get it to work, it says Routing does not exist in the namespace System.Web.
how can I get it to work this way or perhaps another way (web.config?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保您的 Global.asax 有一个 using 语句:
您可以像这样映射您的路线,而无需目标物理 aspx 页面上的参数:
在portfolio.aspx.cs 的代码隐藏中,您可以简单地引用
name
像这样的值:这将确保您的 ASP.NET 4+ 站点的 URL 路由按照您的预期/描述工作。
Ensure your Global.asax has a using statement for:
You can map your route like this without the param on the target physical aspx page:
In the code-behind in portfolio.aspx.cs, you can simply refer to the
name
value like this:This will ensure your ASP.NET 4+ site will have the URL routing working as you expect/describe.