/// <summary> /// 获取Web.Config中的Cookie的超时分钟 /// </summary> /// <returns></returns> public int GetCookieTimeout() { Configuration conn = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null); System.Web.Configuration.AuthenticationSection section = (System.Web.Configuration.AuthenticationSection)conn.SectionGroups.Get("system.web").Sections.Get("authentication"); return(section.Forms.Timeout.Minutes); }
public ActionResult Login(string returnUrl) { //windows登录 //if ((Request.IsAuthenticated && (User.Identity is WindowsIdentity))) //{ // return Redirect("~/Course/index"); //} System.Web.Configuration.AuthenticationSection section = (System.Web.Configuration.AuthenticationSection)System.Web.Configuration.WebConfigurationManager.GetSection("system.web/authentication"); ViewBag.Mode = section.Mode; // ViewBag.UserName = User.Identity.Name; ViewBag.ReturnUrl = returnUrl; return(View()); }
/// <summary> /// 用户登陆成功后,发放表单cookie验证票据并记录用户的相关信息 /// </summary> /// <typeparam name="T">泛型</typeparam> /// <param name="userName">与票证关联的用户名</param> /// <param name="Page">页面对象</param> /// <param name="expiration">FormsAuthenticationTicket过期时间</param> /// <param name="userInfo">要保存在cookie中用户对象</param> public static void UserLoginSetCookie <T>(string userName, Page page, DateTime expiration, T userInfo) { Configuration conn = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/web.config"); System.Web.Configuration.AuthenticationSection section = (System.Web.Configuration.AuthenticationSection)conn.SectionGroups.Get("system.web").Sections.Get("authentication"); expiration = expiration.AddMinutes(section.Forms.Timeout.TotalMinutes); //将对象序列化成字符串 string strUser = JsonHelper.SerializeObject(userInfo); // 设置票据Ticket信息 FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, userName, DateTime.Now, expiration, false, strUser); string strTicket = FormsAuthentication.Encrypt(ticket); // 加密票据 HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, strTicket); // 使用新userdata保存cookie //cookie.Expires = ticket.Expiration;//将票据的过期时间和Cookie的过期时间同步,避免因两者的不同所产生的矛盾 page.Response.Cookies.Add(cookie); }
private void populateConfigModel() { _configModel = new ConfigModel(); _configModel.MemberService = System.Configuration.ConfigurationManager.AppSettings["MemberService"].ToString(); _configModel.LoanServiceEndpoint = System.Configuration.ConfigurationManager.AppSettings["LoanServiceEndpoint"].ToString(); _configModel.SelfReportedServiceEndpoint = System.Configuration.ConfigurationManager.AppSettings["SelfReportedServiceEndpoint"].ToString(); _configModel.AddrValidationServiceEndpoint = System.Configuration.ConfigurationManager.AppSettings["AddrValidationServiceEndpoint"].ToString(); _configModel.SearchServiceEndpoint = System.Configuration.ConfigurationManager.AppSettings["SearchServiceEndpoint"].ToString(); _configModel.AlertServiceEndpoint = System.Configuration.ConfigurationManager.AppSettings["AlertServiceEndpoint"].ToString(); _configModel.ReminderService = System.Configuration.ConfigurationManager.AppSettings["ReminderService"].ToString(); _configModel.SurveyServiceEndpoint = System.Configuration.ConfigurationManager.AppSettings["SurveyServiceEndpoint"].ToString(); _configModel.TemplateDirectory = System.Configuration.ConfigurationManager.AppSettings["TemplateDirectory"].ToString(); /// int minutes = 20; int minutes = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["SessionTimeOut"]); if (minutes == 0) { minutes = 30; } string loginRedirectPage = Url.Content("~/Home"); System.Web.Configuration.AuthenticationSection authSection = (System.Web.Configuration.AuthenticationSection)System.Configuration.ConfigurationManager.GetSection("system.web/authentication"); if (authSection != null && authSection.Forms != null) { // if (authSection.Forms.Timeout != null) ///{ /// minutes = authSection.Forms.Timeout.Minutes; ///} if (!string.IsNullOrEmpty(authSection.Forms.LoginUrl)) { loginRedirectPage = Url.Content(authSection.Forms.LoginUrl); } } _configModel.IsAuthenticated = SiteMember.Account.IsAuthenticated.ToString().ToLower(); _configModel.FormsAuthTimeoutValue = minutes; _configModel.LoginRedirectPage = loginRedirectPage; }
public ActionResult SSOLogin() { // validate the login token that has been passed, retrieve the user credentials and attributes // and return a login token to the IDP so as to respond to a SSO login request. // The second parameter is an arbitrary set of objects that gets passed to the custom id plugin // in this case we pass the controller, so the plugin can figure out who is logged in. IKernel kernel = ASBSSOAdapterModule.GetKernel(); ISSOLoginProcessor ssoLoginProcessor = kernel.Get <ISSOLoginProcessor>(); Dictionary <string, object> paramDictionary = new Dictionary <string, object> { { "controller", this }, { "partnerName", Request[ASBSSOConstants.PARTNERNAME] }, { "optionalParam", Request.Params["optionalParam"] } }; foreach (var param in Request.Params) { // going through all parameters, looking for internships.com "RedirectUrl" parameters, or parameters that start with "utm_" string paramString = param.ToString().Trim(); if (!paramDictionary.ContainsKey(paramString) && (paramString == "UrlSuffix" || paramString.StartsWith("utm_"))) { paramDictionary.Add(paramString, Request.Params[paramString]); } } SSORequestResult result = ssoLoginProcessor.RespondToSSORequest(Request, paramDictionary); HttpCookie saltId = null; //COV 10565 if (System.Web.HttpContext.Current != null) { saltId = System.Web.HttpContext.Current.Request.Cookies["IndividualId"]; } if (saltId != null) { //string RedirectUrl = result.RedirectURL; //int indexStart = RedirectUrl.IndexOf("LoginToken=") + 11; //int indexEnd = RedirectUrl.IndexOf("&AttributeToken"); //string strToken = RedirectUrl.Substring(indexStart, indexEnd - indexStart); //Dictionary<string, string> ssoToken = TokenDecoding.Decode(Server.UrlDecode(strToken), "AES128", "eb64a522b4a9305bb9b6c1358d03c0f8"); if (result.RedirectURL != null) { // indicate that we are in a SSO situation so we can do SSO logout later if needed Session[ASBSSOConstants.ABSSOPARTNER] = Request[ASBSSOConstants.PARTNERNAME]; // redirect to the url that comes back from the adapter. return(Redirect(result.RedirectURL)); } else { throw new Exception("Sorry, SSO Login could not be completed", result.Error); } } else { string loginRedirectPage = Url.Content("~/Home"); System.Web.Configuration.AuthenticationSection authSection = (System.Web.Configuration.AuthenticationSection)System.Configuration.ConfigurationManager.GetSection("system.web/authentication"); if (authSection != null && authSection.Forms != null) { if (!string.IsNullOrEmpty(authSection.Forms.LoginUrl)) { loginRedirectPage = Url.Content(authSection.Forms.LoginUrl); } } loginRedirectPage = loginRedirectPage.Split('?')[0] + "?RetrunUrl=index.html"; return(Redirect(loginRedirectPage)); } }