我正在尝试在我的 asp.net mvc 项目中路由一个 .aspx(webforms 页面).我在 global.asax 中注册页面:
I'm trying to route a .aspx (webforms page) in my asp.net mvc project. I register the page in global.asax:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapPageRoute("Tickets", "Reports/Tickets", "~/WebForms/Reports/Tickets.aspx");
routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional });
问题是,在我添加第二行之后,站点停止进入我的主控制器(索引操作)并重定向到:http://localhost:37538/Reports/Tickets?action=Index&controller=Login%22 总是我运行项目.
The problem is, after i add the second line, the site stops to enter in my Home Controller (Index Action) and is redirecting to: http://localhost:37538/Reports/Tickets?action=Index&controller=Login%22 always that i run the project.
项目详情:
Obs:要重现此错误,请在 /WebForms/Reports 文件夹中创建 Tickets webforms 页面后,创建一个新的 asp.net mvc 项目作为 Internet 应用程序,并注册新路线.运行项目(可能您已登录),现在注销,您将被重定向到 http://localhost:35874/Reports/Tickets?action=LogOff&controller=Account,为什么?
Obs: to reproduce this error, create a new asp.net mvc project as internet app, after create the Tickets webforms page inside a /WebForms/Reports folder, and register the new route. Run the project (probably you're logged), so now logoff and you will be redirected to http://localhost:35874/Reports/Tickets?action=LogOff&controller=Account, so why?
解决了! 所以,我们需要在 webforms 路由中添加一个路由约束,以确保它只捕获传入的路由,而不是传出路由生成.
Solved! So, we need to add a route contraint to the webforms route to ensure that it only catches on incoming routes, not outgoing route generation.
将以下类添加到您的项目中(在新文件中或 global.asax.cs 的底部):
Add the following class to your project (either in a new file or the bottom of global.asax.cs):
public class MyCustomConstraint : IRouteConstraint{
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection){
return routeDirection == RouteDirection.IncomingRequest;
}
}
然后将Tickets路由更改为以下:
Then change the Tickets route to the following:
routes.MapPageRoute(
"Tickets",
"Reports/Tickets",
"~/WebForms/Reports/Tickets.aspx",
true, null,
new RouteValueDictionary { { "outgoing", new MyCustomConstraint() } }
);
这篇关于将 MapPageRoute 添加到 asp.net mvc 项目后,站点停止进入 Home Controller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
ASP.NET Core 使用 Azure Active Directory 进行身份验证并ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 进行身
ASP.NET Core 2.0 Web API Azure Ad v2 令牌授权不起作用ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授权不起作用)
如何获取守护进程或服务器到 C# ASP.NET Web API 的How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何获取守护进程或服务器到 C# ASP.N
异步调用时 Azure KeyVault Active Directory AcquireTokenAAzure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(异步调用时 Azure KeyVault Active Directory AcquireTokenAsync 超
使用电子邮件地址和应用程序密码从 oauth2/tokenGetting access token using email address and app password from oauth2/token(使用电子邮件地址和应用程序密码从 oauth2/token 获取访问令
新的 Azure AD 应用程序在通过管理门户更新之前无New Azure AD application doesn#39;t work until updated through management portal(新的 Azure AD 应用程序在通过管理门户更新之前无法运行