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


C# IHttpRequest.TryResolve方法代码示例

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


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

示例1: AuthenticateIfBasicAuth

 public static void AuthenticateIfBasicAuth(IHttpRequest req, IHttpResponse res)
 {
     var userPass = req.GetBasicAuthUserAndPassword();
     if (userPass != null)
     {
         var authService = req.TryResolve<AuthService>();
         authService.RequestContext = new HttpRequestContext(req, res, null);
         var response = authService.Post(new Auth.Auth {
             provider = BasicAuthProvider.Name,
             UserName = userPass.Value.Key,
             Password = userPass.Value.Value
         });
     }
 }
开发者ID:niemyjski,项目名称:ServiceStack,代码行数:14,代码来源:AuthenticateAttribute.cs

示例2: ResponseFilter

		public void ResponseFilter(IHttpRequest req, IHttpResponse res, object responseDto)
		{
			// all services should return an IHttpResult (tested convention)
			var result = responseDto as IHttpResult;
			if (result == null) throwUnconventionalResult(responseDto);
			else
			{
				if (result.StatusCode == HttpStatusCode.NotFound)
				{
					var log = req.TryResolve<ILogFactory>();

					var ex = new ObjectNotFoundException(((IHttpError) result).ErrorCode);
					log.GetLogger(string.Empty).Warn("No results returned", ex);
				}
			}
		}
开发者ID:dgg,项目名称:Crowdsource-it.org,代码行数:16,代码来源:NotFoundResourceFilter.cs

示例3: AuthenticateIfBasicAuth

        //Also shared by RequiredRoleAttribute and RequiredPermissionAttribute
        public static void AuthenticateIfBasicAuth(IHttpRequest req, IHttpResponse res)
        {
            //Need to run SessionFeature filter since its not executed before this attribute (Priority -100)
            SessionFeature.AddSessionIdToRequestFilter(req, res, null); //Required to get req.GetSessionId()

            var userPass = req.GetBasicAuthUserAndPassword();
            if (userPass != null)
            {
                var authService = req.TryResolve<AuthService>();
                authService.RequestContext = new HttpRequestContext(req, res, null);
                var response = authService.Post(new Auth.Auth {
                    provider = BasicAuthProvider.Name,
                    UserName = userPass.Value.Key,
                    Password = userPass.Value.Value
                });
            }
        }
开发者ID:half-evil,项目名称:ServiceStack,代码行数:18,代码来源:AuthenticateAttribute.cs

示例4: Execute

        public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
        {
            if (AuthService.AuthConfigs == null) throw new InvalidOperationException("The AuthService must be initialized by calling "
                 + "AuthService.Init to use an authenticate attribute");

            var matchingOAuthConfigs = AuthService.AuthConfigs.Where(x =>
                            this.Provider.IsNullOrEmpty()
                            || x.Provider == this.Provider).ToList();

            if (matchingOAuthConfigs.Count == 0)
            {
                res.WriteError(req, requestDto, "No OAuth Configs found matching {0} provider"
                    .Fmt(this.Provider ?? "any"));
                res.Close();
                return;
            }

            var userPass = req.GetBasicAuthUserAndPassword();
            if (userPass != null)
            {
                var authService = req.TryResolve<AuthService>();
                authService.RequestContext = new HttpRequestContext(req, res, requestDto);
                var response = authService.Post(new Auth.Auth {
                    provider = BasicAuthConfig.Name,
                    UserName = userPass.Value.Key,
                    Password = userPass.Value.Value
                });
            }

            using (var cache = req.GetCacheClient())
            {
                var sessionId = req.GetPermanentSessionId();
                var session = sessionId != null ? cache.GetSession(sessionId) : null;

                if (session == null || !matchingOAuthConfigs.Any(x => session.IsAuthorized(x.Provider)))
                {
                    res.StatusCode = (int)HttpStatusCode.Unauthorized;
                    res.AddHeader(HttpHeaders.WwwAuthenticate, "{0} realm=\"{1}\""
                        .Fmt(matchingOAuthConfigs[0].Provider, matchingOAuthConfigs[0].AuthRealm));

                    res.Close();
                }
            }
        }
开发者ID:austinvernsonger,项目名称:ServiceStack,代码行数:44,代码来源:AuthenticateAttribute.cs

示例5: 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

示例6: 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

示例7: AuthenticateIfDigestAuth

        public static void AuthenticateIfDigestAuth(IHttpRequest req, IHttpResponse res)
        {
            //Need to run SessionFeature filter since its not executed before this attribute (Priority -100)
            SessionFeature.AddSessionIdToRequestFilter(req, res, null); //Required to get req.GetSessionId()

            var digestAuth = req.GetDigestAuth();
            if (digestAuth != null)
            {
                var authService = req.TryResolve<AuthService>();
                authService.RequestContext = new HttpRequestContext(req, res, null);
                var response = authService.Post(new Auth.Auth
                {
                    provider = DigestAuthProvider.Name,
                    nonce = digestAuth["nonce"],
                    uri = digestAuth["uri"],
                    response = digestAuth["response"],
                    qop = digestAuth["qop"],
                    nc = digestAuth["nc"],
                    cnonce = digestAuth["cnonce"],
                    UserName = digestAuth["username"]
                });
            }
        }
开发者ID:rajeshpillai,项目名称:ServiceStack,代码行数:23,代码来源:AuthenticateAttribute.cs

示例8: Post

        public static Response<User> Post(this User request,
		                                              Factory factory,
		                                              IHttpRequest httpRequest)
        {

			if(request.IsDummyPassword())
				throw HttpError.Unauthorized("password no válido");

			var authRepo = httpRequest.TryResolve<IUserAuthRepository>();
			if(authRepo==null)
				throw HttpError.NotFound("AuthRepository NO configurado");

			var  user= new UserAuth
			{	
				FirstName= request.FirstName,
				LastName= request.LastName,
				Email= request.Email,
				UserName= request.UserName,
				DisplayName = request.FirstName +" "+ request.LastName
			};
			user.Set<UserMeta>( new UserMeta{
				Cargo= request.Cargo,
				Activo=request.Activo,
				ExpiresAt= request.ExpiresAt
			});

			user = authRepo.CreateUserAuth(user, request.Password);
			request.Id= user.Id;
			request.SetDummyPassword();

			List<User> data = new List<User>();
			data.Add(request);
			
			return new Response<User>(){
				Data=data
			};	
		}
开发者ID:angelcolmenares,项目名称:Aicl.Delfin,代码行数:37,代码来源:BL.User.cs

示例9: Put

        public static Response<User> Put(this User request,
		                                              Factory factory,
		                                              IHttpRequest httpRequest)
        {
			var userSession = httpRequest.GetSession();

			if(!( userSession.HasRole(RoleNames.Admin) ||
				    userSession.HasPermission("User.update") ))
				throw HttpError.Unauthorized("Usuario no autorizado para actualizar");


			var authRepo = httpRequest.TryResolve<IUserAuthRepository>();
			if(authRepo==null)
				throw HttpError.NotFound("AuthRepository NO configurado");

			var  user= authRepo.GetUserAuth(request.Id.ToString());

			if (!(request.Id== int.Parse(userSession.UserAuthId) ||
				userSession.HasRole(RoleNames.Admin)) )
				throw HttpError.Unauthorized("No puede cambiar los datos de otro usuario");

			if(user == default(UserAuth))
				throw HttpError.NotFound(
					string.Format("Usuario con Id:'{0}' NO encontrado",request.Id));


			var  newUser= new UserAuth
			{	
				Id= request.Id,
				FirstName= request.FirstName,
				LastName= request.LastName,
				Email= request.Email,
				UserName= request.UserName,
				DisplayName= request.FirstName+" "+request.LastName,
				ModifiedDate= System.DateTime.Now,
			};
			newUser.Set<UserMeta>( new UserMeta{
				Cargo= request.Cargo,
				Activo=request.Activo,
				ExpiresAt= request.ExpiresAt
			});

			if(request.Password.IsNullOrEmpty() 
			   ||  request.IsDummyPassword()){

				factory.Execute(proxy=>{

					proxy.Update<UserAuth>(
						newUser,
						ev=>ev.Where(q=>q.Id==request.Id).
					Update(f=> new {
						f.UserName, f.FirstName, f.LastName, f.Email, f.Meta,
						f.DisplayName,
						f.ModifiedDate
					}));
				});

			}

			else
				user = authRepo.UpdateUserAuth(user, newUser,request.Password);

			request.SetDummyPassword();

			List<User> data = new List<User>();
			data.Add(request);
			
			return new Response<User>(){
				Data=data
			};	
		}
开发者ID:angelcolmenares,项目名称:Aicl.Delfin,代码行数:71,代码来源:BL.User.cs

示例10: UpdateFromUserAuthRepo

        public static void UpdateFromUserAuthRepo(this IAuthSession session, IHttpRequest req, IUserAuthRepository userAuthRepo = null)
        {
            if (userAuthRepo == null)
                userAuthRepo = req.TryResolve<IUserAuthRepository>();

            if (userAuthRepo == null) return;

            var userAuth = userAuthRepo.GetUserAuth(session, null);
            session.UpdateSession(userAuth);
        }
开发者ID:rajeshpillai,项目名称:ServiceStack,代码行数:10,代码来源:SessionExtensions.cs


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