【问题标题】:ReturnUrl not working when using MapPageRoute in webform在 web 表单中使用 MapPageRoute 时 ReturnUrl 不起作用
【发布时间】:2014-10-25 10:51:04
【问题描述】:

我有一个使用 ASP.NET 4.5 和 ASP.net Identity 2.0 开发的现有 Web 应用程序。我在 RouteConfig.cs 中有这样的路由器设置:

public static void RegisterRoutes(RouteCollection routes)
{
   var settings = new FriendlyUrlSettings();
   settings.AutoRedirectMode = RedirectMode.Permanent;
   routes.EnableFriendlyUrls(settings);
   routes.MapPageRoute("manage-user-acc", "manage-user-acc", "~/Account/Manage.aspx", true);
}

manage.aspx 页面必须登录才能查看。当应用程序运行时,我在地址栏中输入 url,如下所示:

http://localhost:64296/manage-user-acc

returnUrl 不起作用,错误是

访问提供此服务所需的资源时出错 要求。您可能没有查看请求的权限 资源。

但是当我在地址栏中输入这样的网址时

http://localhost:64296/Account/Manage

returnUrl 正在工作并返回登录页面,如下所示:

http://localhost:64296/Account/Login?ReturnUrl=%2Faccount%2Fmanage

所以任何人都可以帮助我找出我在哪里做错了。或者如何调试所有进程

【问题讨论】:

    标签: asp.net webforms forms-authentication


    【解决方案1】:

    这看起来像一个错误。您可以通过验证路由而不是物理页面来绕过它。删除调用 MapPageRoute 中的布尔值

    routes.MapPageRoute("manage-user-acc", "manage-user-acc", "~/Account/Manage.aspx");
    

    并在根 Web.config 中拒绝未经身份验证的路由访问

    <location path="manage-user-acc">
        <system.web>
            <authorization>
                <deny users="?"/>
            </authorization>
        </system.web>
    </location>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多