2013-05-31 39 views
1

在我的應用程序一個編碼器加入到全球ASAX 的功能,雖然它不叫任何地方,當我嘗試PostAuthResponse調用此 和Request.IsAuthenticated是返回false,所以我的代碼給錯誤 這是錯誤集Context.User的東西在Application_PostAuthenticateRequest

at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) 
    at System.Net.HttpWebRequest.GetRequestStream() 
    at ePayment.cc5payment.processorder() 

這是全球ASAX代碼。如何把一個虛擬用戶到Context.User

protected void Application_PostAuthenticateRequest() 
    { 
     if (Request.IsAuthenticated) 
     { 
      Context.User = System.Threading.Thread.CurrentPrincipal = 
       new AuthorizationPrincipal(Context.User.Identity); 
     } 
    } 

回答

1

你應該做到以下幾點:

protected void Application_PostAuthenticateRequest() 
{ 
    if (Request.IsAuthenticated) 
    { 
     GenericIdentity identity = new 
         GenericIdentity("some_user_name","my_authentication"); 
     Context.User = new GenericPrincipal(genericIdentity, new string[]{}); 
                 //this is a list of roles. 
    } 
} 

你應該閱讀有關MSDN上的GenericPrincipal類。

+0

我可以使用它*** ADFS ***和*** OWIN ***,'System.Security.Claims.ClaimsIdentity'? – Kiquenet