Server.Transfer from WebForms ashx handler to MVC 3
I'm trying to do a Server.Transfer from an ASP.NET ashx handler开发者_如何转开发 to a ASP.NET MVC 3 page.
I don't want to use Server.Redirect because I do not want the URL to change.
Is this possible?
You may try the following in your generic HTTP handler:
public void ProcessRequest(HttpContext context)
{
var routeData = new RouteData();
routeData.Values["controller"] = "Home";
routeData.Values["action"] = "Index";
IController controller = new HomeController();
controller.Execute(new RequestContext(new HttpContextWrapper(context), routeData));
}
Obviously this would only work if the Generic HTTP handler is part of the ASP.NET MVC application.
If it is not the same application an HTTP redirect is your only bet.
精彩评论