add a path cgi-bin to asp.net mvc

时间:2024-05-24 12:36:32

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);
}