MapPageRoute()在文件夹中路由aspx页面时出错404错误

时间:2014-04-17 21:09:25

标签: c# asp.net webforms

尝试在webforms中路由,获得404。 我使用System.Web.Routing;

设置了我的global.asax.cs文件,如下所示
protected void Application_Start(object sender, EventArgs e)
        {
            RegisterRoutes(RouteTable.Routes);
        }

        private void RegisterRoutes(RouteCollection routes)
        {
            routes.MapPageRoute("ProfilePage",
            "Profile",
            "~/Manager/Profile.aspx");
        }

profile.aspx位于manager文件夹中。不知道为什么它不起作用。如果有人能提出一些我对asp.net相当新的建议,我将不胜感激。

我希望网址localhost:60008/Manager/Profile/加载Profile.aspx页面。

2 个答案:

答案 0 :(得分:0)

第二个参数指定URL。尝试:

routes.MapPageRoute("ProfilePage",
                    "Manager/Profile",
                    "~/Manager/Profile.aspx");

答案 1 :(得分:0)

你第一次就做对了。这是一个有效的路由

routes.MapPageRoute("", "YourPage", "~/Your/full/url.aspx", true);

第一个para可以是空的,第二个是你要使用的那个,第三个是你的页面的url,最后一个[可选]是检查文件是否存在。

我相信错误的来源是你如何使用它,对于你想说的超链接

NavigateUrl="~/YourPage"

在html锚中

href="~/YourPage" runat="server"

在浏览器地址栏中,它会显示为http://YourDomain.com/YourPage/

这就是它对我有用的方式。个人不得不把文件夹放在那里打败了使用路由no的目的?