C# asp.net中的登录表单不会直接指向登录页面

C# asp.net中的登录表单不会直接指向登录页面,c#,asp.net,webforms,C#,Asp.net,Webforms,基本上,我正在使用VisualStudio中提供的登录表单,并尝试使用sql数据库进行身份验证。如果我输入了不正确的数据,则会显示正确的验证,但是当我输入正确的数据时,它只刷新当前表单,而不是记录destinationUrl部分 我现在不知道如何解决这个问题…救命 以下是我的表格代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI;

基本上,我正在使用VisualStudio中提供的登录表单,并尝试使用sql数据库进行身份验证。如果我输入了不正确的数据,则会显示正确的验证,但是当我输入正确的数据时,它只刷新当前表单,而不是记录destinationUrl部分

我现在不知道如何解决这个问题…救命

以下是我的表格代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data;
using System.Data.SqlClient;

namespace com.tortoise.Admin.AdminViews
{
public partial class WebForm1 : System.Web.UI.Page
{
    private string strcon = WebConfigurationManager.ConnectionStrings["TortoiseDBConnectionString"].ConnectionString;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
        private bool UserLogin(string un, string pw)
    {
        SqlConnection con = new SqlConnection(strcon);
        SqlCommand cmd = new SqlCommand("Select Username from Admins where Username=@un and Password=@pw", con);
        cmd.Parameters.AddWithValue("@un", un);
        cmd.Parameters.AddWithValue("@pw", pw);
        con.Open();
        string result = Convert.ToString(cmd.ExecuteScalar());
        if (string.IsNullOrEmpty(result)) return false; return true;
    }
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        string un = Login1.UserName;
        string pw = Login1.Password;
        bool result = UserLogin(un, pw);
        if (result)
        {
            e.Authenticated = true;
            Session["username"] = un;
            Login1.DestinationPageUrl =
           String.Format("Manager.aspx?{0}", Request.QueryString.ToString());

        }

        else e.Authenticated = false;
    }

    protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {

    }
}
}试试这个:

string returnUrl = Request.QueryString["ReturnUrl"];
 if (returnUrl == null) returnUrl = @"~/yourfirstpage.aspx";
     Response.Redirect(returnUrl);
试试这个:

string returnUrl = Request.QueryString["ReturnUrl"];
 if (returnUrl == null) returnUrl = @"~/yourfirstpage.aspx";
     Response.Redirect(returnUrl);

请尝试
String.Format(“~/Manager.aspx?{0}”,…
我一直使用
响应。重定向
我从来没有使用过任何东西,q字符串一直被填充,重定向总是自动的。可能需要在web.config中添加一些内容,sry我现在忘记了什么,或者删除并重新添加登录控件。另外,您可以在管理区域使用单独的登录和web.config。谢谢大家。将尝试您的一些建议。将返回结果try
String.Format(“~/Manager.aspx?{0}”,…
我一直使用
响应。重定向
我从来没有使用过任何东西,q字符串一直被填充,重定向总是自动的。可能需要在web.config中添加一些内容,sry我现在忘记了什么,或者删除并重新添加登录控件。另外,您可以在管理区域使用单独的登录和web.config。谢谢大家。我们将尝试您的一些建议。我们将返回结果