首页 新闻 会员 周边

asp.net管理系统给客户分配不同的账号,客户登陆后跳转到不同的页面

0
悬赏园豆:30 [已解决问题] 解决于 2012-01-12 15:21

0123用户类型是跳转到同一页面的,用panel控件隐藏,4和5要跳转到新的页面A.aspx和B.aspx.
现在只能跳转到C.aspx页面,怎么更改代码才让能让4跳转到A.aspx,5跳转到B.aspx呢,菜鸟求教...
protected void Page_Load(object sender, EventArgs e)
{
if (Session["userType"] != null)
{
// Response.Write(Session["userType"].ToString());
if (Session["userType"].ToString().Trim()=="0")
{
//PanelAdmin.Visible = false;
}
if (Session["userType"].ToString().Trim() == "1")
{
PanelSuper.Visible = false;
}
if (Session["userType"].ToString().Trim() == "2" || Session["userType"].ToString().Trim() == "3" || Session["userType"].ToString().Trim() == "4" || Session["userType"].ToString().Trim() == "5")
{
PanelSuper.Visible = false;
PanelAdmin.Visible = false;
}
HiddenFieldK.Value = FormsAuthentication.HashPasswordForStoringInConfigFile(Session["userType"]+"ty2010", "MD5");
HiddenFieldU.Value = Session["userType"].ToString();
HiddenFieldI.Value = Session["userID"].ToString();
}
else {
Response.Redirect("/Login.html");
}
--------------------------------------
function doLogin()
{
$.ajax({
url: "LoginHandler.ashx?t="+Math.random(),
global: false,
type: "POST",
data: ( { login: $("#login").val(), password:$("#pwd").val()}),
async:false,
success: function (msg)
{
if (msg == 'true')
{
window.location = "C.aspx";
} else
{
alert("登陆失败!"); }

},
error:function(errmsg,textStatus)
{
alert("无法登陆!");
}
});
}
lqps的主页 lqps | 初学一级 | 园豆:44
提问于:2012-01-10 09:17
< >
分享
最佳答案
1
你上面写的Page_Load是哪个页面下的?你可能需要修改LoginHandler.ashx里面的方法,现在是通过帐号和密码返回true或false,然后是true就跳到C.aspx。你需要修改成返回一个字符串,比如返回0表示登录失败,返回1表示跳转到c.aspx,返回2表示跳转到A.aspx,返回3表示跳转到B.aspx。改完LoginHandler.ashx后,你再改写doLogin方法。如下:
function doLogin()
{
$.ajax({
url: "LoginHandler.ashx?t="+Math.random(),
global: false,
type: "POST",
data: ( { login: $("#login").val(), password:$("#pwd").val()}),
async:false,
success: function (msg)
{
if (msg == '1')
{
window.location = "C.aspx";
} else if (msg == '2')
{
window.location = "A.aspx";
}else if (msg == '3')
{
window.location = "B.aspx";
}
else
{
alert("登陆失败!"); }

},
error:function(errmsg,textStatus)
{
alert("无法登陆!");
}
});
}
收获园豆:30
LCM | 大侠五级 |园豆:6876 | 2012-01-10 09:29

老兄,得再麻烦你一下哈 本人确实菜..Page_Load是母版页下的, 下面的是LoginHandler.ashx

public class LoginHandler : IHttpHandler,IRequiresSessionState
{
public void ProcessRequest (HttpContext context)
{
context.Response.ContentType = "text/plain";
if (context.Request["login"] != null && context.Request["password"] != null)
{
string sql = ConfigurationManager.ConnectionStrings["ty2010ConnectionString"].ConnectionString;//连接数据
SqlConnection conn = new SqlConnection(sql);
conn.Open();
SqlCommand command = new SqlCommand("getUser", conn);//getUser存储过程
command.CommandType = CommandType.StoredProcedure;
SqlParameter spLogin = new SqlParameter("login", SqlDbType.NVarChar);
SqlParameter spPwd = new SqlParameter("password", SqlDbType.NVarChar);
spLogin.Value = context.Request["login"];
spPwd.Value = FormsAuthentication.HashPasswordForStoringInConfigFile(context.Request["password"], "MD5");

command.Parameters.Add(spLogin);
command.Parameters.Add(spPwd);
SqlDataReader sdr = command.ExecuteReader();
if (sdr.Read())
{
context.Response.Write("true");
context.Session["userType"] = sdr["Type"].ToString();//userType用户类型
context.Session["userID"] = sdr["ID"].ToString();
}
else
{
context.Response.Write("false");
}
}
else
{
context.Response.Write("false");
}
}
public bool IsReusable
{
get
{
return false;
}
}
}

 

lqps | 园豆:44 (初学一级) | 2012-01-10 09:54

@lqps: doLogin方法就按我上面写的。然后LoginHandler中的ProcessRequst方法改成这样试一下。

public void ProcessRequest (HttpContext context)
{
context.Response.ContentType = "text/plain";
if (context.Request["login"] != null && context.Request["password"] != null)
{
string sql = ConfigurationManager.ConnectionStrings["ty2010ConnectionString"].ConnectionString;//连接数据
SqlConnection conn = new SqlConnection(sql);
conn.Open();
SqlCommand command = new SqlCommand("getUser", conn);//getUser存储过程
command.CommandType = CommandType.StoredProcedure;
SqlParameter spLogin = new SqlParameter("login", SqlDbType.NVarChar);
SqlParameter spPwd = new SqlParameter("password", SqlDbType.NVarChar);
spLogin.Value = context.Request["login"];
spPwd.Value = FormsAuthentication.HashPasswordForStoringInConfigFile(context.Request["password"], "MD5");

command.Parameters.Add(spLogin);
command.Parameters.Add(spPwd);
SqlDataReader sdr = command.ExecuteReader();
if (sdr.Read())
{
//context.Response.Write("true");
string type=sdr["Type"].ToString();
context.Session["userType"] = type;//userType用户类型
context.Session["userID"] = sdr["ID"].ToString();
switch (type)
{
case "4":
context.Response.Write("2");
break;
case "5":
context.Response.Write("3");
break;
default:
context.Response.Write("1");
break;
}
}
else
{
context.Response.Write("0");
}
}
else
{
context.Response.Write("0");
}
}
LCM | 园豆:6876 (大侠五级) | 2012-01-10 10:03

@LCM: 终于可以了 实在非常的感谢啊....

lqps | 园豆:44 (初学一级) | 2012-01-10 11:00
其他回答(1)
0

关键看你LoginHandler.ashx里的代码才知道

artwl | 园豆:16736 (专家六级) | 2012-01-10 09:33
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册