我的网站托管在here:以上但是当我登录时,地址栏中的网址会不断重复并且变得更长,如:this,如果您点击左侧菜单,那么您可以看到地址栏,URL越来越大。请在上面建议我为什么URL会变得这么大?
请找到以下网站凭证: 用户名:int123 密码:123
以下是代码示例:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Request.QueryString["type"] == "logout")
{
Session.Clear();
Response.Cookies.Clear();
//FormsAuthentication.SignOut();
Response.Redirect("http://103.252.236.33/plesk-site-preview/2wayglobal.com/103.252.236.33/login.aspx");
}
}
}
protected void btnLogin_Click(object sender, EventArgs e)
{
string username = string.Empty;
string userid = string.Empty;
string address = string.Empty;
string company = string.Empty;
if ((txtUsername.Value.Trim() == string.Empty || txtUsername.Value.Trim() == "Username") && (txtPassword.Value.Trim() == string.Empty || txtPassword.Value.Trim() == "Password"))
{
//divError.Visible = true;
lblError.Text = "Please type the correct username and password";
ResetFields();
}
else if (txtUsername.Value.Trim() == string.Empty || txtUsername.Value.Trim() == "Username")
{
//divError.Visible = true;
lblError.Text = "User name is incorrect.";
ResetFields();
}
else if (txtPassword.Value.Trim() == string.Empty || txtPassword.Value.Trim() == "Password")
{
//divError.Visible = true;
lblError.Text = "Password is incorrect.";
ResetFields();
}
else
{
DataTable dtuserLogin = db.GetLoginDetails(txtUsername.Value.Trim(), txtPassword.Value.Trim());
try
{
if (dtuserLogin.Rows.Count > 0)
{
userid = Convert.ToString(dtuserLogin.Rows[0]["srno"]).Trim();
username = Convert.ToString(dtuserLogin.Rows[0]["username"]).Trim();
company = Convert.ToString(dtuserLogin.Rows[0]["company"]).Trim();
address = Convert.ToString(dtuserLogin.Rows[0]["address"]).Trim();
//FormsAuthentication.SetAuthCookie(username + ";" + company + ";" + address, true);
}
}
catch (Exception ex)
{
throw new Exception("Error in btnLogin_Click()" + ex.Message);
}
if (username == "admin")
{
Response.Redirect("http://103.252.236.33/plesk-site-preview/2wayglobal.com/103.252.236.33/Admin/Default.aspx", true);
}
else
{
Response.Redirect("http://103.252.236.33/plesk-site-preview/2wayglobal.com/103.252.236.33/User/Default.aspx", true);
}
}
}
private void ResetFields()
{
txtUsername.Value = "Username";
txtPassword.Value = "Password";
}
答案 0 :(得分:0)
只是btn click事件结束时的代码会将您重定向到该URL:
if (username == "admin")
{
Response.Redirect("http://103.252.236.33/plesk-site-preview/2wayglobal.com/103.252.236.33/Admin/Default.aspx", true);
}
else
{
Response.Redirect("http://103.252.236.33/plesk-site-preview/2wayglobal.com/103.252.236.33/User/Default.aspx", true);
}
答案 1 :(得分:0)
我看不到导致问题的代码,但是我打赌$ 1你正在调用Redirect
并传递你认为的绝对URL,但实际上是一个相对URL。浏览器将重定向视为相对,只是添加到地址栏中已有的URL末尾的路径。它会一遍又一遍地执行此操作,直到URL溢出其缓冲区并且出现Bad Request
错误。
而不是
Response.Redirect("AbsolutePath/PageName.aspx") //This is a relative URL!
你应该使用
Response.Redirect("~/AbsolutePath/PageName.aspx")
或
Response.Redirect("/AbsolutePath/PageName.aspx")
或
Response.Redirect("https://ServerName.com/AbsolutePath/PageName.aspx")
......取决于你想要完成的事情。