【问题标题】:Return URL not working in link返回 URL 在链接中不起作用
【发布时间】:2014-10-11 12:18:42
【问题描述】:

我正在使用 ASP.net,但在登录后重定向原始请求的 URL 时遇到问题。 URL 清楚地显示在地址栏中,但在签名时,每次都会将我带到 Default.aspx:

http://development-4/login.aspx?ReturnUrl=%2fControls%2fFinancial%2fAddressBook.aspx

【问题讨论】:

  • 你是怎么做这个重定向的?
  • 根据您请求的页面,它似乎只是在会话过期后才执行。
  • 你如何重定向? FormsAuthentication.RedirectFromLoginPage("userName", isPersistant);
  • 只是 Response.Redirect

标签: c# asp.net url webforms


【解决方案1】:

.NET 框架已经使用“ReturnUrl”值自动处理重定向。除非您将用户带到他们试图去的地方以外的地方,否则请使用以下命令将他们重定向到他们请求的页面。

将“userName”替换为他们在登录时提供的用户名。“isPersistant”指的是 cookie 是应该保留浏览器会话还是在其窗口关闭时被删除。

FormsAuthentication.RedirectFromLoginPage("userName", isPersistant); 

如果您选择将用户带到其他地方,您的代码应该与此类似。

FormsAuthentication.SetAuthCookie("userName", isPersistant);
Response.Redirect("~/SomePage.aspx");

由于您没有提供太多背景信息,我将添加以下配置。你应该有类似的东西。

<system.web>
    <authentication mode="Forms">
        <forms name="loginCookieName" loginUrl="~/login.aspx" protection="All" timeout="60" path="/" />
    </authentication>
    <authorization>
        <deny users="?" />
    </authorization>
</system.web>
<location path="login.aspx">
    <system.web>
        <authorization>
            <allow users="*" />
        </authorization>
    </system.web>
</location>

【讨论】:

    猜你喜欢
    • 2010-09-26
    • 2010-09-27
    • 1970-01-01
    • 1970-01-01
    • 2014-04-29
    • 2017-09-03
    • 2014-05-04
    • 2014-03-07
    • 1970-01-01
    相关资源
    最近更新 更多