SSO.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net;
  6. using System.IO;
  7. using Bowin.Common.JSON;
  8. using System.Web;
  9. namespace EMISOnline.Utility.FormValidate
  10. {
  11. public static class SSO
  12. {
  13. public static string SSOLogin()
  14. {
  15. string fromUrl = "";
  16. string currentUrl = HttpContext.Current.Request.Url.AbsoluteUri;
  17. string getTicketUrl = Const.SSO_HOST + "Account/GetTicket?url=" + currentUrl;
  18. string authUrl = Const.SSO_HOST + "Account/AuthTicket";
  19. string ticket = HttpContext.Current.Request["ticket"];
  20. if (HttpContext.Current.Request.UrlReferrer != null)
  21. {
  22. fromUrl = HttpContext.Current.Request.UrlReferrer.AbsolutePath;
  23. }
  24. if (ticket == null && !fromUrl.StartsWith(Const.SSO_HOST))
  25. {
  26. HttpContext.Current.Response.Redirect(getTicketUrl);
  27. return "";
  28. }
  29. else if (ticket == null && fromUrl.StartsWith(Const.SSO_HOST))
  30. {
  31. return "";
  32. }
  33. else
  34. {
  35. WebRequest webRequest = (HttpWebRequest)WebRequest.Create(authUrl + "?ticket=" + ticket);
  36. webRequest.Method = "POST";
  37. webRequest.ContentType = "text/json";
  38. webRequest.ContentLength = 0;
  39. StreamReader sr = new StreamReader(webRequest.GetResponse().GetResponseStream());
  40. string loginID = sr.ReadToEnd();
  41. sr.Close();
  42. return loginID.JsonToObject<string>();
  43. }
  44. }
  45. }
  46. }