Global.asax 中的 ASP.NET 路由 [英] ASP.NET Routing in Global.asax

查看:27
本文介绍了Global.asax 中的 ASP.NET 路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按照以下步骤在我的 Web 表单应用程序中添加路由:

I'm trying to add a route in my web forms application by following this:

http://msdn.microsoft.com/en-us/library/cc668201.aspx#adding_routes_to_a_web_forms_application

我在 Global.asax 文件中添加了路由,如下所示:

I've added the route in my Global.asax file like so:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.MapPageRoute("", "/WebsiteName/{combinedPin}", "~/Default.aspx");
}

然后我尝试像这样在本地访问我的网站:

I then try to visit my website locally like this:

http://localhost:12345/WebsiteName/test36u

http:// localhost:12345/WebsiteName/test36u

但我收到一条无法找到资源的消息,所以我认为我的路线不正确.有人能看到我的代码有问题吗?

But I get a resource cannot be found message so I don't think my route is correct. Can anybody see a problem with my code?

任何指针将不胜感激.

谢谢

推荐答案

你不需要在路由中指定你的网站名称,试试这个代码:

You do not need to specify the name of your website as part of the route, try with this code:

routes.MapPageRoute("", "{combinedPin}", "~/Default.aspx");

使用上述代码,您的链接将如下所示:

With the above code, your link would look like:

http://localhost:12345/WebsiteName/test36u

然而,如果您的意图是您的用户使用名为:WebsiteName 的段访问您的网站,则使用:

If however your intention is that your users access your site using a segment named: WebsiteName then use:

routes.MapPageRoute("", "WebsiteName/{combinedPin}", "~/Default.aspx");

但是在前面的代码中,您的用户必须按如下方式访问您的资源:(尽管可能不是预期的结果)

But in the precedent code your users will have to access your resource as follows: (probably not the expected result though)

http://localhost:12345/WebsiteName/WebsiteName/test36u

这篇关于Global.asax 中的 ASP.NET 路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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