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

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

问题描述

我想通过以下这在我的Web窗体应用程序添加路由:

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

<一个href=\"http://msdn.microsoft.com/en-us/library/cc668201.aspx#adding_routes_to_a_web_forms_application\">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://本地主机:12345 / WebsiteName / test36u

http:// localhost:12345/WebsiteName/test36u

但我得到一个资源无法找到的消息,所以我不认为我的路线是正确的。任何人都可以看到一个问题,我的code?

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?

任何指针将是非常美联社preciated。

Any pointers would be much appreciated.

感谢

推荐答案

您并不需要指定网站的名称作为路线的一部分,试试这个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");

通过上面的code,你的链接看起来像:

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");

但在precedent code您的用户必须访问你的资源如下:(可能不是预期,虽然结果)

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

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

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