add a path cgi-bin to asp.net mvc

 

 1.简单,但是会丢失请求数据

  protected void Application_BeginRequest()
        {
            string url = HttpContext.Current.Request.Url.AbsoluteUri.ToString();
            if (url.ToLower().Contains("cgi-bin"))
            {
                HttpContext.Current.Response.Redirect(url.Replace("-",""));
            }
        }

 

 2.把请求数据转发到目标action

                url = HttpContext.Current.Request.Url.AbsolutePath.Replace("-", "");
                HttpContext context = System.Web.HttpContext.Current;
                if (HttpRuntime.UsingIntegratedPipeline)
                {
                    context.Server.TransferRequest(url, true);
                }
                else
                {
                    // Pre MVC 3
                    context.RewritePath(url, false);

                    IHttpHandler httpHandler = new MvcHttpHandler();
                    httpHandler.ProcessRequest(context);
                }

 

 

 

 

posted @ 2014-01-13 11:51  zyip  阅读(407)  评论(0编辑  收藏  举报