2013-09-27 34 views
0

我爲我的測試項目創建庫。 當我創建庫項目時,命名空間不工作。 請幫助MembershipUser不工作

#地區(獲取登錄的用戶ID)

static public Guid GetUserId() 
    { 
     Guid guUser = Guid.Empty; 

     try 
     { 
      MembershipUser muUser = Membership.GetUser(); 
      if (muUser != null) 
      { 
       guUser = (Guid)muUser.ProviderUserKey; 
       Membership.GetUser(guUser, true); 
      } 
      else 
      { 
       //Log out and redirect to login page 
       FormsAuthentication.SignOut(); 
       FormsAuthentication.RedirectToLoginPage(); 
      } 
     } 
     catch (Exception ex) 
     { 
      ApplicationError.LogErrors(ex); 
     } 

     return guUser; 
    } 

    #endregion 

回答

0

如果在單元測試解決方案測試,這是行不通的,因爲你的單元測試解決方案必須具有相同的config文件的最後應用項目。否則,它完美的作品。

+0

只要做到這一點,但在您的單元測試項目中創建一個.config文件,並將其配置爲與您的exe或web項目相同的方式。 – Softlion