gpt4 book ai didi

c# - ASP.NET Response.Redirect with jQuery Mobile - Url hashing

转载 作者:太空狗 更新时间:2023-10-29 17:58:36 24 4
gpt4 key购买 nike

我有一个标准表单例份验证 ASP.NET 应用程序。我的注册和登录页面与 2 个 jQuery Mobile 页面位于同一个 .aspx 文件中。如果我回发我的 ASP.NET 页面,例如用户无法正确登录...等,Url 哈希开始一遍又一遍地附加到自身。

示例网址:
http://localhost:56644/Register.aspx?ReturnUrl=%2fDefault.aspx%3fbla%3dtest&bla=test#Register.aspx?ReturnUrl=%2fDefault.aspx%3fbla%3dtest&bla=test/p>

一旦我的用户通过身份验证,我想在没有所有哈希信息的情况下重定向到 ReturnUrl,或者找到一种方法让 url 在回发期间保留?

标记:

<div data-role="page" id="register">
<div data-role="content" data-scroll="true" data-theme="b" class="Content">
......
<a href='#login'>Login</a
</div>
</div>
<div data-role="page" id="login">
<div data-role="content" data-scroll="true" data-theme="b" class="Content">
.....
<a href='#register' >Registered Yet?</a>
</div>
</div>

Register.aspx 上的代码隐藏:

protected void btnLogin_Click(object sender, EventArgs e)
{
if (LoggedIn)
{
FormsAuthentication.SetAuthCookie("blabla", true);
//Note: Request.QueryString["ReturnUrl"] = "/Default.aspx?bla=test";
Response.Redirect(Request.QueryString["ReturnUrl"]);

}
}

最佳答案

这是一篇旧帖子,但遇到了同样的问题,我将发布我已经制定的解决方案 - 它有点粗糙,但它可能对某人有所帮助或有所改进。此外,它在 ASP.NET MVC 4 中 - 不确定如何将相同的代码迁移到 aspx

我基本上做的是捕获 RedirectTo URL 并使用它作为 LogOn 表单标记的 data-url 属性提供。换句话说,在 MVC 4 中:

  1. 我将 LogOn.csthml 的副本创建为 LogOn.Mobile.cshtml
  2. 在 LogOn.Mobile.cshtml 中添加以下内容::

     @{
    string landPage = Request.Url.Query.Length>11?
    Request.Url.Query.Substring(11):"";//very rough, to be improved.
    // Here I am clipping the RedirectTo prefix of the Query
    }
    //replaces the boilerplate @using (Html.BeginForm())
    @using (Html.BeginForm("LogOn", "Account", FormMethod.Post,
    new { @data_url = landPage}))

这应该足以让它工作

关于c# - ASP.NET Response.Redirect with jQuery Mobile - Url hashing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6864162/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com