Exemplo n.º 1
0
        private static object MapParameter(IOwinContext ctx, RequestElement source, string parameterName, Type type)
        {
            switch (source)
            {
            case RequestElement.Route:
                return(ctx.GetRouteValue(parameterName).UnescapeUriString().ToType(type));

            case RequestElement.Query:
                return(ctx.Request.Query.Get(parameterName).UnescapeUriString().ToType(type));

            case RequestElement.Header:
                return(ctx.Request.Headers.Get(parameterName).ToType(type));

            case RequestElement.Body:
                return(ctx.GetBodyValue(parameterName).ToType(type));

            default:
                throw new NotSupportedException();
            }
        }
Exemplo n.º 2
0
        private static object FindParameterValue(IOwinContext ctx, string parameterName)
        {
            var s = ctx.GetRouteValue(parameterName);

            if (!string.IsNullOrEmpty(s))
            {
                return(s.UnescapeUriString());
            }

            s = ctx.Request.Query.Get(parameterName);
            if (!string.IsNullOrEmpty(s))
            {
                return(s.UnescapeUriString());
            }

            if (!ctx.Request.Method.Equals("GET", StringComparison.OrdinalIgnoreCase))
            {
                return(ctx.GetBodyValue(parameterName));
            }
            return(null);
        }