我無法獲得authenticationService的工作。當我嘗試從我的winforms應用程序調用Authentication_JSON_AppService.axd時,我不斷收到404錯誤。所以我最終編寫了自己的JSON身份驗證WebMethod。
對不起,這不是C#,我的項目是VB.NET。我用這個http://progtutorials.tripod.com/Authen.htm作爲參考。
<WebMethod(EnableSession:=True)>
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)>
Public Function Login(ByVal username As String, ByVal password As String) As Boolean
Dim result As Boolean = False
' If (FormsAuthentication.Authenticate(username,password)) ' this may also work to authenticate
If (Membership.ValidateUser(username, password)) Then
FormsAuthentication.SetAuthCookie(username, False)
Dim ticket As FormsAuthenticationTicket = New FormsAuthenticationTicket(username, False, 30)
Dim ticketString As String = FormsAuthentication.Encrypt(ticket)
Dim cookie As HttpCookie = New HttpCookie(FormsAuthentication.FormsCookieName, ticketString)
Context.Response.Cookies.Add(cookie)
result = True
End If
Return result
End Function
一定要讓您的web服務中的匿名用戶可以訪問您的身份驗證WebService。
<location path="Authentication.asmx">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
您是否使用Authentication_JSON_AppService.axd作爲AUTH_SERVICE_URL? 404例外有什麼問題嗎? – 2012-02-17 16:56:10
我使用Authentication_JSON_AppService.axd/Login作爲AUTH_SERVICE_URL。 – 2012-02-20 18:10:33
感謝您的回覆。是的,我試過了。無論出於何種原因,我無法使Authentication_JSON_AppService.axd/Login正常工作。編寫自定義身份驗證WebMethod非常簡單。 – 2012-02-20 19:09:22