2011-11-29 43 views
4

當我得到引用URL時,IIS 7引發異常。我的代碼是這樣的:IIS 7 UrlReferrer拋出異常

var referrer = Request.UrlReferrer == null ? null : Request.UrlReferrer.AbsoluteUri; 

應用拋出錯誤消息一個ArgumentException,

「值沒有在預期範圍之內。」

有IIS 6中

網頁時用「的Response.Redirect」

應用程序主頁面已經根據當前的角色的Response.Redirect方法導航發生此異常沒有問題用戶。用戶主頁引發此異常。

在IIS中如何獲得引薦網址7.

感謝,

回答

3

跑進類似的問題時,我試圖從請求處理推出了System.Threading.Task訪問請求對象。 我正在使用該任務來減少響應時間 - 在我的情況下,大多數處理可以在請求發送後執行。 即,我必須是這樣的:

public ActionResult SomeAction() 
{ 
    new System.Threading.Task(() => { 

     // here I used this.Request.UrlReferrer and got weird ArgumenException error 

    }).Start(); 

    return someActionResultThatDoesntRequireProcessing; 
} 

我萃取UrlReferrer(和其他this.Request.stuff我需要)在延遲處理)到一個單獨的「封閉」變量(我選擇他們有非常基本的類型):

public ActionResult SomeAction() 
{ 
    var urlReferrerAbs = this.Request.UrlReferrer.AbsoluteUri; 
    var clientAddress = this.Request.UserHostAddress; 
    // save other stuff from the request object 

    new System.Threading.Task(() => { 

     // here I used urlReferrerAbs instead of this.Request.UrlReferrer and the error has gone! 

    }).Start(); 

    return someActionResultThatDoesntRequireProcessing; 
} 

這對我有效。

+0

因此,我必須在重定向頁面之前獲取引薦網址。 – selami

+0

也許,因爲正確獲取所有Request屬性的某些上下文可能在重定向後以及在切換到另一個線程之後丟失。 – LVR

+0

異步登錄問題。問題已經解決了。謝謝。 – selami