当前位置: 首页>>代码示例>>C#>>正文


C# IHttpRequest.SaveSession方法代码示例

本文整理汇总了C#中IHttpRequest.SaveSession方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpRequest.SaveSession方法的具体用法?C# IHttpRequest.SaveSession怎么用?C# IHttpRequest.SaveSession使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IHttpRequest的用法示例。


在下文中一共展示了IHttpRequest.SaveSession方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

		public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
		{
			base.Execute(req, res, requestDto);
			var session = req.GetSession();
			if(session!=null && session.IsAuthenticated)
			{
				req.SaveSession(session);// refresh session TTL
			}
		}
开发者ID:angelcolmenares,项目名称:Aicl.Colmetrik,代码行数:9,代码来源:RequiresAuthenticateAttribute.cs

示例2: HasAllRoles

        public bool HasAllRoles(IHttpRequest req, IAuthSession session, IAuthRepository userAuthRepo=null)
        {
            if (HasAllRoles(session)) return true;

            session.UpdateFromUserAuthRepo(req, userAuthRepo);

            if (HasAllRoles(session))
            {
                req.SaveSession(session);
                return true;
            }
            return false;
        }
开发者ID:qqqzhch,项目名称:ServiceStack,代码行数:13,代码来源:RequiredRoleAttribute.cs

示例3: HasAllRoles

        public bool HasAllRoles(IHttpRequest req, IAuthSession session, IUserAuthRepository userAuthRepo=null)
        {
            if (HasAllRoles(session)) return true;

            if (userAuthRepo == null)
                userAuthRepo = req.TryResolve<IUserAuthRepository>();

            if (userAuthRepo == null) return false;

            var userAuth = userAuthRepo.GetUserAuth(session, null);
            session.UpdateSession(userAuth);

            if (HasAllRoles(session))
            {
                req.SaveSession(session);
                return true;
            }
            return false;
        }
开发者ID:niemyjski,项目名称:ServiceStack,代码行数:19,代码来源:RequiredRoleAttribute.cs

示例4: Execute

		public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
		{
			base.Execute(req, res, requestDto);
			var session = req.GetSession();
			if(session!=null && session.IsAuthenticated)
			{
				req.SaveSession(session);// refresh session TTL
				var cache = req.TryResolve<IRedisClientsManager>();
				if(cache!=null){
					using(var client = cache.GetClient()){
						var pattern = string.Format("urn:{0}:*", req.GetSessionId());
						var keys =client.SearchKeys(pattern);
						foreach(var k in keys) {
							client.ExpireEntryIn(k, AuthProvider.DefaultSessionExpiry);
						}
					}
				}
			}
		}
开发者ID:aicl,项目名称:Cayita.Tools,代码行数:19,代码来源:RequiresAuthenticateAttribute.cs

示例5: ApiSignIn

 public static void ApiSignIn(ref Container container, ref IHttpRequest req, ref IHttpResponse res)
 {
     if (req.QueryString["apikey"] != null)
     {
         var repository = container.Resolve<IRepository>();
         var authRepo = (OrmLiteAuthRepository)container.Resolve<IUserAuthRepository>();
         int userAuthId = int.Parse(req.QueryString["apikey"].Split('|')[0]);
         string apiKey = req.QueryString["apikey"].Split('|')[1];
         var users = repository.Find<User>(u => u.UserAuthId == userAuthId && u.ApiKey == apiKey);
         if (users.Count() > 0)
         {
             UserAuth userAuth = authRepo.GetUserAuthByUserName(users[0].UserName);
             CustomUserSession user = userAuth.TranslateTo<CustomUserSession>();
             user.IsAuthenticated = true;
             user.UserAuthId = users[0].UserAuthId.ToString();
             req.SaveSession(user);
         }
     }
 }
开发者ID:voxon2,项目名称:Razor.ServiceStack-On-Azure,代码行数:19,代码来源:CustomUserSession.cs

示例6: AutoSignIn

 public static void AutoSignIn(ref Container container, ref IHttpRequest req, ref IHttpResponse res)
 {
     string authSession = string.Empty;
     if (req.Cookies.ContainsKey("auth-session"))
     {
         if (string.IsNullOrEmpty(req.Cookies["auth-session"].Value))
         {
             authSession = "0";
             res.Cookies.DeleteCookie("auth-session");
         }
         else
         {
             authSession = req.Cookies["auth-session"].Value;
         }
     }
     if (!req.GetSession().IsAuthenticated && !string.IsNullOrEmpty(authSession))
     {
         // Auto sign-in the user:
         var repository = container.Resolve<IRepository>();
         var authRepo = (OrmLiteAuthRepository)container.Resolve<IUserAuthRepository>();
         int userAuthId = int.Parse(authSession.Split('|')[0]);
         string apiKey = authSession.Split('|')[1];
         var users = repository.Find<User>(u => u.UserAuthId == userAuthId && u.ApiKey == apiKey);
         if (users.Count() > 0)
         {
             UserAuth userAuth = authRepo.GetUserAuthByUserName(users[0].UserName);
             CustomUserSession user = userAuth.TranslateTo<CustomUserSession>();
             user.IsAuthenticated = true;
             user.UserAuthId = users[0].UserAuthId.ToString();
             req.SaveSession(user);
         }
     }
     else if (req.GetSession().IsAuthenticated && string.IsNullOrEmpty(authSession))
     {
         // Create the auto sign-in coookie:
         var repository = container.Resolve<IRepository>();
         int userAuthId = int.Parse(req.GetSession().UserAuthId);
         User user = repository.Find<User>(u => u.UserAuthId == userAuthId).FirstOrDefault();
         res.Cookies.AddPermanentCookie("auth-session", req.GetSession().UserAuthId + "|" + user.ApiKey);
     }
 }
开发者ID:voxon2,项目名称:Razor.ServiceStack-On-Azure,代码行数:41,代码来源:CustomUserSession.cs


注:本文中的IHttpRequest.SaveSession方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。