以下是实现的效果图:
首先上图的点击火车订票链接,就会打开学生信息平台网站/LoginToTrainSite.asa页面。
LoginToTrainSite.asa页面的大致代码如下:
复制代码 代码如下:
<%
Response.Buffer = True
Response.ExpiresAbsolute = Now() - 1
Response.Expires = 0
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "No-Cache"
//根据用户session获取用户名和密码
%>
<html>
<body>
<div>
<form method="post" action="http://火车订票网站/LoginFromOtherSite.aspx">
<input type="hidden" value="<%=userName%>" />
<input type="hidden" value="<%=userPwd%>" />
</form>
</div>
</body>
</html>
<script language="javascript">
myForm.submit();
</script> LoginFromOtherSite.aspx.cs页面的代码大致如下:
using (SqlConnection conn = new SqlConnection(SqlHelper.StudentConnectionString))
{
string sql = "select t_stuUser.ID, t_stuUser.stuNumber, t_stuUser.userPassword, t_stuUser.realName, v_stuUser.className, v_stuUser.departmentName "
+ "from t_stuUser,v_stuUser where t_stuUser.stuNumber=@UserName and t_stuUser.userPassword=@UserPwd and v_stuUser.stuNumber=@UserName";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter pUserName = cmd.Parameters.Add("@UserName", SqlDbType.VarChar, 30);
SqlParameter pUserPwd = cmd.Parameters.Add("@UserPwd", SqlDbType.VarChar, 150);
pUserName.Value = Request.Form["UserName"];
pUserPwd.Value = Request.Form["UserPwd"];
conn.Open();
SqlDataReader sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (sdr.Read())
{
Session["UserID"] = Convert.ToString(sdr["ID"]);
Session["StuName"] = Convert.ToString(sdr["realName"]);
Session["StuNumber"] = Convert.ToString(sdr["stuNumber"]);
Session["Academe"] = Convert.ToString(sdr["departmentName"]);
Session["ClassName"] = Convert.ToString(sdr["className"]);
Response.Redirect("MyOrder.aspx"); // 登录成功
}
else
{
Response.Redirect("Default.aspx"); //登录失败,用户名或密码错误
}
}
新闻热点
疑难解答
图片精选