ASP.NET Routing in Global.asax(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 路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Global.asax 中的 ASP.NET 路由


- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 输入按键事件处理程序 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04