|
|
|
สอบถามเกี่ยวกับ SSO ProGram หน่อยครับ User Authen บน AD |
|
|
|
|
|
|
|
ถ้ามีระบบที่เป็น Client 1 ตัวแล้วผมต้องทำหน้าเว็บ SSO โดยหลังจาก Login ครั้งแรก แล้วมี Button ให้กดเข้าตัวโปรแกรม Client นั้น และผมไม่ต้อง login อีกรอบ สามารถทำได้ไหมครับ ทำไมผมโยนค่าไปไม่ผ่าน
Code (C#)
if (Session["sAMAccountName"] != null && Session["Password"] != null)
{
string user = Session["sAMAccountName"].ToString();
this.Username.Value = user;
string pass = Session["Password"].ToString();
this.Password.Value = pass;
//Test Cookie//
HttpCookie httpCookie = FormsAuthentication.GetAuthCookie("sAMAccountName", true);//Persistent Cookie
httpCookie.Domain = "xxx.xxx.xxx";//Set the domain
HttpContext.Current.Response.Cookies.Add(httpCookie);// add the auth cookie to response
//Response.Redirect(FormsAuthentication.GetRedirectUrl("sAMAccountName", true));
httpCookie["sAMAccountName"] = user;
httpCookie["Password"] = pass;
Response.Cookies.Add(httpCookie);
//End Test Cookie//
//Test//
string postbackUrl = "https://xxx.xxx.xxx.xxx/mediasite/LoginForm/Login.aspx";
string ssoTime = DateTime.Now.ToString("yyyyMMddHHmmss");
string ssoUsername = user;
string ssoSharedSecret = "";
string ssoHash = FormsAuthentication.HashPasswordForStoringInConfigFile(string.Format("{0},{1},{2}",ssoSharedSecret,ssoTime,ssoUsername),"md5");
string value = string.Format("{0},{1},{2}",ssoHash,ssoTime,ssoUsername);
Response.Clear();
StringBuilder sb = new StringBuilder();
sb.Append("<html>");
sb.AppendFormat(@"<body onload='document.forms[""form""].submit()'>");
sb.AppendFormat("<form name='form' action='{0}' method='post'>", postbackUrl);
sb.AppendFormat("<input type='hidden' name='t' value='{0}'>", value);
sb.Append("</form>");
sb.Append("</body>");
sb.Append("</html>");
Response.Write(sb.ToString());
Response.End();
Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), VS 2010 (.NET 4.x)
|
|
|
|
|
|
Date :
2014-01-14 11:35:17 |
By :
offonepoint |
View :
942 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ส่งไปแบบนี้ก็ยังไม่ไปอ่ะคับ ตัว CMS นั้น เป็น c# เหมือนกัน อ่ะใครมีวิธีอื่น ลอง Share หน่อยคับ
Code (C#)
protected void Page_Load(object sender, EventArgs e)
{
if (Session["sAMAccountName"] != null && Session["Password"] != null)
{
string user = Session["sAMAccountName"].ToString();
this.UserName.Value = user;
string pass = Session["Password"].ToString();
this.Password.Value = pass;
//Test Cookie//
HttpCookie httpCookie = FormsAuthentication.GetAuthCookie("sAMAccountName", true);//Persistent Cookie
httpCookie.Domain = "xxx.xxx.xxx";//Set the domain
HttpContext.Current.Response.Cookies.Add(httpCookie);// add the auth cookie to response
//Response.Redirect(FormsAuthentication.GetRedirectUrl("sAMAccountName", true));
httpCookie["sAMAccountName"] = user;
httpCookie["Password"] = pass;
Response.Cookies.Add(httpCookie);
//End Test Cookie//
//Test//
string postbackUrl = "https://xxx.xxx.xxx.xxx/mediasite/LoginForm/Login.aspx";
string ssoTime = DateTime.Now.ToString("yyyyMMddHHmmss");
string ssoUsername = user;
string ssoPassword = pass; // Test
string ssoSharedSecret = "ef43be11-ffef-4e6f-a506-6275af16fa08";
string ssoHash = FormsAuthentication.HashPasswordForStoringInConfigFile(string.Format("{0},{1},{2},{3}",ssoSharedSecret, ssoTime, ssoUsername,ssoPassword), "md5");
string value = string.Format("{0},{1},{2},{3}", ssoHash, ssoTime, ssoUsername,ssoPassword);
//Response.Clear();
StringBuilder sb = new StringBuilder();
sb.Append("<html>");
sb.AppendFormat(@"<body onload='document.forms[""form""].submit()'>");
sb.AppendFormat("<form name='form' action='{0}' method='post'>", postbackUrl);
//sb.AppendFormat("<input type='hidden' name='t' value='{0}'>", value);
sb.AppendFormat("<input type='hidden' id='UserName' value='{0}'>", ssoUsername);
sb.AppendFormat("<input type='hidden' id='Password' value='{0}'>", ssoPassword);
sb.Append("</form>");
sb.Append("</body>");
sb.Append("</html>");
Response.Write(sb.ToString());
//Response.End();
//End Test//
}
}
|
|
|
|
|
Date :
2014-01-14 15:24:35 |
By :
offonepoint |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|