protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { String OAuthSite = ConfigurationManager.AppSettings["OAuthSite"]; DataSet Ds = DataSetXML.XmlDocumentToDataSet(ConfigurationManager.AppSettings["OAuthSite"]); this.RptListSSOWebSite.BindDataSource(Ds.Tables["JosonPost"]); } }
/// <summary> /// Action执行前判断 /// </summary> /// <param name="filterContext"></param> protected override void OnActionExecuting(ActionExecutingContext filterContext) { #region OnActionExecuting OAuthURL = Net.Common.ConfigHelper.GetConfig("OAuthURL"); GetToken = Net.Common.ConfigHelper.GetConfig("GetToken"); AccountLogin = Net.Common.ConfigHelper.GetConfig("AccountLogin"); TokenService = Net.Common.ConfigHelper.GetConfig("TokenService"); OAuthCorrectMsg = Net.Common.ConfigHelper.GetConfig("OAuthCorrectMsg"); TokenCorrectMsg = Net.Common.ConfigHelper.GetConfig("TokenCorrectMsg"); TokenCorrectRedirectURL = Net.Common.ConfigHelper.GetConfig("TokenCorrectRedirectURL"); if (Session["Token"] != null) { //分站凭证存在 //Response.Write("恭喜,分站凭证存在,您被授权访问该页面!"); Response.Write(OAuthCorrectMsg); } else { //分站凭证不存在 //令牌验证结果 if (Request.QueryString["Token"] != null) { #region 令牌检查 if (Request.QueryString["Token"] != "$Token$") { //持有令牌 string tokenValue = Request.QueryString["Token"]; string strRedirect = Request.QueryString["Redirect"]; //调用WebService获取主站凭证 object result = null; if (tokenValue.NotIsNullOrEmpty()) { #region 令牌存在从数据库 获取数据 #region Joson Test //string strURL = "http://www.webxml.com.cn/WebServices/ChinaZipSearchWebService.asmx"; //string ServiceName = "getAddressByZipCode"; //string[] args = new string[2]; //args[0] = "723112"; //args[1] = ""; //Net.Common.ResponseWebServices.InvokeWebService(strURL, ServiceName, args); #endregion //string JosonURL ="http://www.passport.com/TokenService.asmx"; string JosonURL = TokenService; string JosonServiceName = "TokenGetCredences"; string[] JosonArgs = new string[1]; JosonArgs[0] = tokenValue; JosonServiceName = "TokenGetCredencDt"; //JosonServiceName = "TokenGetCredence"; try { result = Net.Common.ResponseWebServices.InvokeWebService(JosonURL, JosonServiceName, JosonArgs); #region Joson Test Hashtable HashTab = new Hashtable(); HashTab.Add("tokenValue", tokenValue); System.Xml.XmlDocument XMLResult = ResponseWebServices.QueryGetWebService(JosonURL, JosonServiceName, HashTab); DataSet Ds = DataSetXML.XmlDocumentToDataSet(XMLResult); JosonURL = "http://www.webxml.com.cn/WebServices/ChinaZipSearchWebService.asmx"; JosonServiceName = "getAddressByZipCode"; HashTab.Add("theZipCode", "723000"); HashTab.Add("userID", ""); XMLResult = ResponseWebServices.QueryGetWebService(JosonURL, JosonServiceName, HashTab); Ds = DataSetXML.XmlDocumentToDataSet(XMLResult); #endregion } catch (Exception ex) { //千萬不能用這句 //throw new Exception(String.Format("登录验证错误:{0}", ex.Message)); } #endregion } #region 令牌验证 if (result != null) { //令牌正确 Session["Token"] = result; Response.Write(TokenCorrectMsg); // Response.Write("恭喜,令牌存在,您被授权访问该页面!"); if (strRedirect != null || strRedirect.NotIsNullOrEmpty()) { Response.Redirect(strRedirect); } else if (TokenCorrectRedirectURL.NotIsNullOrEmpty()) { Response.Redirect(TokenCorrectRedirectURL); } } else { //令牌错误 重新登录验证 Response.Redirect(this.replaceToken()); } #endregion } else { //未持有令牌 重新登录验证 Response.Redirect(this.replaceToken()); } #endregion } else { //未进行令牌验证,去主站验证 Response.Redirect(this.getTokenURL()); } } #endregion //this.HostUrl = "http://" + this.Request.Url.Host; //this.HostUrl += this.Request.Url.Port.ToString() == "80" ? "" : ":" + this.Request.Url.Port; //this.HostUrl += this.Request.ApplicationPath; //List<string> ActionNameList = new List<string>(); //ActionNameList.Add("GetWebName"); //ActionNameList.Add("Login"); //// 判断是否登录 //if (!this.checkLogin() && !ActionNameList.Contains(filterContext.ActionDescriptor.ActionName)) //{ // filterContext.Result = RedirectToRoute("Home", new { Controller = "Login", Action = "Index" }); //} base.OnActionExecuting(filterContext); }
public void ClearToken() { //清除本地Cookie HttpCookie AccountCookie = new HttpCookie("AccountID"); AccountCookie.Values.Add("Value", ""); Response.AppendCookie(AccountCookie); #region 通知分站做退出操作 String OAuthSite = ConfigurationManager.AppSettings["OAuthSite"]; DataSet Ds = DataSetXML.XmlDocumentToDataSet(ConfigurationManager.AppSettings["OAuthSite"]); if (Ds.Tables["Joson"].Rows.Count > 0) { foreach (DataRow Dr in Ds.Tables["Joson"].Rows) { try { String HttpGet = Dr["httpGet"].ToStrings(); //GetRequest.GetPageResouceCode(HttpGet); HttpRequestHander.HttpGet(HttpGet); Response.Redirect(HttpGet); } catch (Exception ex) { continue; } } } #endregion //清空主站凭证 if (Request.QueryString["Token"] == null) { //Response.Redirect("http://www.passport.com/gettoken.aspx?BackURL=" + Server.UrlEncode(Request.Url.AbsoluteUri + "?Token=$Token$")); Response.Redirect(GetToken + "?BackURL=" + Server.UrlEncode(Request.Url.AbsoluteUri + "?Token=$Token$")); } else { if (Request.QueryString["Token"] != "$Token$") { string token = Request.QueryString["Token"]; //创建WebService对象 //String strURL = "http://www.passport.com/TokenService.asmx"; String strURL = TokenService; String ServiceName = "ClearToken"; string[] args = new string[1]; args[0] = token; object o = Net.Common.ResponseWebServices.InvokeWebService(strURL, ServiceName, args); } //清空本地凭证 Session.Abandon(); Response.Redirect("index.aspx"); Response.Write("已退出!"); } }