C# 如何:在httpHandler中执行控制器方法(mvc4)
我有MVC4应用程序,它包含http处理程序,我想将用户重定向到我的第一页 控制器C# 如何:在httpHandler中执行控制器方法(mvc4),c#,asp.net-mvc,httphandler,ihttphandler,C#,Asp.net Mvc,Httphandler,Ihttphandler,我有MVC4应用程序,它包含http处理程序,我想将用户重定向到我的第一页 控制器 public class HomeController : Controller { public ActionResult Index() { return View(); } } HttpHandler public class MyPublicHandler : IHttpHandler { public void ProcessRequest(HttpCo
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}
HttpHandler
public class MyPublicHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
if (condition)
{
var controller = new HomeController();
controller.Index(); // redirect and execute
}
// or something like that
if (condition)
{
ExecutePage("http://myWebSite/Home/Index")
}
}
}
谢谢 您真的想要重定向(HTTP 302),还是只想发送view Index.cshtml呈现的HTML?你能不能再多告诉我一点你为什么要这么做?也许这比使用HttpHandler容易得多。用户已经将指向本地计算机的链接添加到书签中,所以这种类型的。我解析ItemId=10,若未找到项,则需要重定向用户