Response.Redirect is showing /Account/Login?ReturnUrl=%2f

本文关键字:ReturnUrl %2f Login Account Redirect is showing Response | 更新日期: 2023-09-27 18:15:11

我是struct与重定向的东西在我的asp.net web应用程序与c#。

当我进入登录页面并完成所有功能,然后重定向到下一页的url /Login?ReturnUrl=%2f显示。

所以我用谷歌搜索了这个问题,并在web.config

中添加了这些行
  <appSettings>
    <add key="autoFormsAuthentication" value="false" />
    <add key="enableSimpleMembership" value="false"/>
  </appSettings>
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="43280" />
    </authentication>

但是当我做Response.Redirect("SelectApp.aspx");时仍然显示相同的url,其中SelectApp.aspx是放置在帐户文件夹下的webform,其中Login.aspx也放置。

   protected void LoginButton_Click(object sender, EventArgs e)
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from UserMaster where USER_NAME =@username and USER_PWD1=@password", con);
            //string enPwd = Encode(Password.Text);
            cmd.Parameters.AddWithValue("@username", UserName.Text);
            cmd.Parameters.AddWithValue("@password", Password.Text);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                Response.Redirect("SelectApp.aspx");
            }
            else
            {
                ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>");
            }
        }

我已经添加了上面的代码。

Response.Redirect is showing /Account/Login?ReturnUrl=%2f

在重定向到"SelectApp.aspx"之前。尝试添加FormsAuthentication.SetAuthCookie(UserName.Text.Trim(), false);

这只是一个猜测,试试:aspx",假);

主要是因为结束响应可能会干扰身份验证…

我没有测试过,但我记得遇到过类似的问题。将'endResponse'参数设置为'false'就可以了。

检查您的web的授权标签。配置,甚至可能在认证时你对类型有任何限制:

<authorization>
    <deny users = "*" />
</authorization>