【问题标题】:Routing in ASP.net Web forms with id parameters带有 id 参数的 ASP.net Web 表单中的路由
【发布时间】:2020-10-26 18:42:56
【问题描述】:

我在我的 RouteConfig.cs 中注册了这个 MapPageRoute

        routes.MapPageRoute(
            "ProfileRoute",
            "Profile/{userid}",
            "~/Profile.aspx"
            );

这就是我使用 id 参数重定向到个人资料页面的方式(从登录到个人资料)

Response.Redirect(GetRouteUrl("ProfileRoute", new { userid = usersign.Text }));

但是,它显示错误“'/' 应用程序中的服务器错误。”和“找不到资源” 请求的 URL 看起来像“请求的 URL:/Profile/id”

我之前用过下面的Route方法

Response.Redirect(String.Format("Profile.aspx?id={0}", id));

但我想将其更改为更好、更稳定的路由方法,它在某种程度上类似于 MVC 路由。

我可以在我的代码中修复哪些错误?以及如何在 Web 表单中实现我的目标?

【问题讨论】:

    标签: c# asp.net asp.net-mvc webforms routes


    【解决方案1】:

    我自己想通了。 我从 RouteConfig.cs 中删除了以下代码

                routes.MapRoute(
                    name: "Default",
                    url: "{controller}/{action}/{id}",
                    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
                );
    

    成功了

    我不需要这段代码(现在),因为我还没有创建任何控制器。除非我需要它们,否则我想这段代码对我的项目来说并没有多大必要。

    【讨论】:

      猜你喜欢
      • 2016-11-19
      • 2015-10-09
      • 2017-08-30
      • 2010-10-20
      • 2012-04-17
      • 2014-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多