コード例 #1
0
        private static HttpContextBase FakeHttpContext(string url, HttpVerbs?httpMethod, HttpVerbs?formMethod)
        {
            NameValueCollection form = null;

            if (formMethod.HasValue)
            {
                form = new NameValueCollection {
                    { "_method", formMethod.Value.ToString().ToUpper() }
                }
            }
            ;

            if (!httpMethod.HasValue)
            {
                httpMethod = HttpVerbs.Get;
            }

            int idx = url.LastIndexOf('?');
            NameValueCollection queryString = null;

            if (idx > -1)
            {
                queryString = new QueryString(QueryString.ExtractQuerystring(url));
                url         = url.Substring(0, idx);
            }

            var httpMethodStr = httpMethod.Value.ToString().ToUpper();
            var context       = new FakeHttpContext(url, httpMethodStr, null, form, queryString, null, null, null);

            return(context);
        }