2013-06-29 88 views
0

有沒有辦法攔截asp.net ajax webmethods(aspx頁面靜態方法)?攔截asp.net ajax webmethod

我想在請求到達方法之前以及在發送響應之後攔截。

+1

什麼是你想之前和之後做什麼? –

回答

0

使用

protected void Application_BeginRequest(Object sender, EventArgs e) 
    { 
     //before method colling 
     string ss = HttpContext.Current.Request.Url.ToString();//use if it is equal to your page webmethod url i.e. domain.com/dfault.aspx/GetMessage; 
if(ss=="http://domain.com/dfault.aspx/GetMessage") 
{ 
do your work here 
} 
    } 

    protected void Application_EndRequest(Object sender, EventArgs e) 
    { 
     //after method colling 
     string ss = HttpContext.Current.Request.Url.ToString();// use if it is equal to your page webmethod i.e. domain.com/dfault.aspx/GetMessage;; 

if(ss=="http://domain.com/dfault.aspx/GetMessage") 
{ 
do your work here 
} 
    } 
+0

感謝您的回答,這將幫助我,但如果我想攔截每個webmethod是否有任何方法?因爲這個解決方案我必須寫很多條件。有什麼辦法可以檢測出它是webmethod還是普通的頁面請求? – user1935868