gpt4 book ai didi

asp.net-mvc - ASP.NET MVC 应用程序路由不适用于动态数据 WebForm 页面

转载 作者:行者123 更新时间:2023-12-01 16:56:08 25 4
gpt4 key购买 nike

我需要正确的 Global.asax 设置,以便我的动态数据站点能够在 ASP.NET MVC 项目下运行。目前路由似乎是我的问题。

这是我的 global.asax:

public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

MetaModel model = new MetaModel();
model.RegisterContext(typeof(Models.DBDataContext), new ContextConfiguration() { ScaffoldAllTables = true });
routes.Add(new DynamicDataRoute("DD/{table}/{action}.aspx") {
Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
Model = model
});

routes.MapRoute(
"Assignment",
"Assignment/{action}/{page}",
new { controller = "Assignment", action = "Index", page = "" });

routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Admin", action = "Index", id = "" }); // Parameter defaults

}

我尝试使用的链接是:

http://localhost:64205/DD/Work_Phases/ListDetails.aspx

我收到以下消息:

Server Error in '/' Application. The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /DD/Work_Phases/ListDetails.aspx

我尝试用 DynamicData 替换 DD,因为应用程序内部的文件夹是 DynamicData 并且产生了完全相同的结果。

最佳答案

网址

http://localhost:64205/DD/Work_Phases/ListDetails.aspx

正在匹配您的第二条(默​​认)路线,该路线正在尝试访问名为“DD”的 Controller 。

您可能需要另一个类似这样的路由条目:

routes.MapRoute(
"DD",
"DD/{action}/{page}",
new { controller = "NameOfController", action = "Index", page = "" }
);

...虽然我无法想象为什么你需要传递页面参数。命中的页面 View 取决于 Controller 方法的返回操作。


要更好地了解动态数据与 ASP.NET MVC 的集成,请查看 Scott Hanselman's Plugin-Hybrids article.他有一些关于处理不属于 MVC 的 .ASPX 文件的详细信息。特别是,如果您不希望 ASP.NET MVC Controller 处理 .ASPX,则可以安装忽略路由:

routes.IgnoreRoute("{myWebForms}.aspx/{*pathInfo}");

应该注意的是,ASP.NET MVC 开箱即用地配置为忽略对磁盘上物理存在的文件的 URL 请求,尽管 Scott 的 IgnoreRoute 技术显然更有效。

关于asp.net-mvc - ASP.NET MVC 应用程序路由不适用于动态数据 WebForm 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1215221/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com