2011-08-18 36 views
2

我們正在將我們的舊Webapp從WebForms移植到MVC Asp.net,我已經創建了用於基本報告的舊應用程序的HttpHandlers。如何在MVC Asp.Net中調用HttpHandler?

我們直接打電話給他們,即www.something.com/handler.ashx?ID=1上的按鈕點擊。

現在我需要在MVC Asp.Net中移植相同的功能,編寫處理程序是一件容易的任務,但是如何處理查詢字符串並將請求傳遞給Handler?

+0

檢查http://forums.asp.net/t/1320309.aspx/1?How+to+use+a+custom+HttpHandler+in+MVC+它可能包含答案 –

回答

2
  1. 您可以像其他應用程序一樣使用處理函數,不需要使用它的路由。
  2. 如果以IIS7集成模式運行應用程序,則必須在system.webServer部分的處理程序元素(httpHandlers部分適用於IIS6和IIS7經典模式)中定義http處理程序。
  3. 還檢查http://blog.maartenballiauw.be/post/2008/05/ASPNET-MVC-custom-ActionResult.aspx,它具有一個圖像操作結果,它僅使用標準的ASP.NET MVC生命週期。

http://forums.asp.net/t/1320309.aspx/1?How+to+use+a+custom+HttpHandler+in+MVC+

0

我有以下行添加到我的RouteConfig類,以避免訪問一個ashx的處理程序時得到一個404錯誤複製。該處理程序在Web.config中註冊,因此不使用ashx文件,所以另一個解決方案是使用.axd擴展。

public class RouteConfig 
{ 
    public static void RegisterRoutes(RouteCollection routes) 
    { 
     // MVC routing is ignoring .axd paths by default. 
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

     // This line added to also ignore .ashx files. 
     routes.IgnoreRoute("{resource}.ashx/{*pathInfo}"); 

     // ... 
    } 
} 
相關問題