2014-01-25 64 views
1

我在將身份驗證部署到IIS 7生產Web服務器時遇到問題。我使用內存身份驗證,當我從Visual Studio本地運行時,一切正常。然而,當我嘗試連接到Web服務器產品,從使用ServiceStack客戶WPF應用程序,我得到不同的錯誤,包括:將ServiceStack身份驗證部署到IIS時出現問題7

  • 「未找到」
  • 「未授權」
  • 「{」長度不能小於零。參數名稱:長度「}」

我已經嘗試過許多IIS身份驗證配置,包括啓用/禁用窗體身份驗證,Windows身份驗證和基本身份驗證,都無濟於事。

  • 我有時可以使用CodeInChaos.com REST客戶端進行連接。
  • 密碼和用戶名絕對正確。

global.asax

public override void Configure(Funq.Container container) 
{ 
    RegisterPlugins(); 
    RegisterValidators(container); 
    RegisterCaches(container); 
    RegisterSessionFactories(container); 
    RegisterRepositories(container); 
    RegisterUsers(container); 
} 

private void RegisterPlugins() 
{ 
    Plugins.Add(new AuthFeature(() => new AuthUserSession(),new IAuthProvider[] { new BasicAuthProvider()})); 
}   

private void RegisterUsers(Funq.Container container) 
{ 
    var userRepository = new InMemoryAuthRepository(); 
    container.Register<IUserAuthRepository>(userRepository); 

    string hash; 
    string salt; 

    new SaltedHash().GetHashAndSaltString("xxxxxxxx", out hash, out salt); 
    userRepository.CreateUserAuth(new UserAuth 
    { 
     Id = 1, 
     DisplayName = "xxx xxxxxx", 
     Email = "[email protected]", 
     UserName = ""xxxxxxxx, 
     FirstName = "xxxx", 
     LastName = "xxxx", 
     PasswordHash = hash, 
     Salt = salt, 
     Roles = new List<string> { RoleNames.Admin }, 
    }, "xxxxxxxx"); 
} 

我的客戶:

public UserEntity GetUserFromDomainUsername(string domainUsername) 
{ 
    try 
    { 
     using (var client = new StormJsonServiceClient(WebServiceUrl){UserName = "xxxxxxx", Password = "xxxxxxxx"}) 
     { 
      var response = client.Send(new UserFromDomainUsernameQuery { DomainUsername = domainUsername }); 
      return response.User; 
     } 
    } 
    catch (Exception exception) 
    { 
     var ex = exception as WebServiceException; 
     if (ex != null) 
     { 
      throw new VqsWebServiceException(GetWebServiceErrorMessage(ex)); 
     } 
     throw; 
    } 
} 
+0

發佈你的'web.config'。確保你在'AppHost'配置中啓用'DebugMode = true',這樣你就可以獲得有用的堆棧跟蹤。 IIS身份驗證與ServiceStack身份驗證無關,如果您不需要它,請將其關閉。你說你得到3個不同的錯誤,據推測你提出了3個不同的請求,而不是3次提出相同的請求?您最好部署一個簡單的應用程序,即無需身份驗證的應用程序,以測試您是否正確設置了IIS配置,因爲這是您的第一個部署,如果這樣可行,啓用身份驗證。 – Scott

+1

嗨斯科特 - 謝謝。相信與否,這就是答案......只需關閉除匿名之外的IIS中的所有身份驗證,它就可以工作。非常感謝您的指導。 Simon – smlemmon

+0

太好了。我已經爲這個效果添加了一個答案,所以你可以關閉這個問題,所以其他人可以很容易地識別出有什麼幫助。祝你的項目好運。 – Scott

回答

1

IIS的身份驗證是沒有關係的ServiceStack驗證,關閉它,如果你不需要它。

如果您啓用了IIS身份驗證,它將在您的ServiceStack應用程序之上有效運行。所以它會在所有對你的ServiceStack服務的請求之前運行,並且你最終必須首先滿足這個安全標準。如果通過,您的請求將通過ServiceStack應用程序。

大多數在ServiceStack中實現身份驗證的人不需要IIS來實現身份驗證。