我創建了一個簡單的 WCF Web 服務,并要求將用戶名/密碼添加到服務中的 WCF 安全性,并閱讀了以下 MS 檔案
如果你想看這個類,這里??是它的代碼:
Imports System.IdentityModel.Selectors
Public Class CustomUserNameValidator
Inherits UserNamePasswordValidator
Public Overrides Sub Validate(ByVal userName As String, ByVal password As String)
If userName Is Nothing OrElse password Is Nothing Then
Throw New ArgumentNullException()
End If
If Not (userName = "user" AndAlso password = "pass123") Then
Throw New FaultException("Unknown Username or Incorrect Password")
End If
End Sub
End Class
此外,這就是檔案屬性中顯示的全部內容。

如果您能幫助解決錯誤,將不勝感激。
uj5u.com熱心網友回復:
您必須確保“Cu??stomUserNameValidator.vb”屬性上的“構建操作”設定為“編譯”。根據您所描述的內容,它似乎設定在“內容”上。
該影像顯示了如何執行此操作或在此處查看:

uj5u.com熱心網友回復:
我遇到上述問題的原因是因為我需要在 web.config 中設定它
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="CustomUserNameValidator, App_Code" />
</serviceCredentials>
當我在我的機器上轉到以下路徑時,唯一的 dll 是 App_Code.tjgywzog.dll 所以認為程式集只是 App_Code 然后它只需要使用類名 CustomUserNameValidator 因為我的代碼沒有使用命名空間。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/520129.html
上一篇:使用SqlAdapter更新表
