我剛剛更新了我的MVC2項目以運行MVC3(RC)。除了一個問題,一切都按預期工作。ASP.NET MVC3 - ActionResult呈現DotNetOpenAuth WebResponse作爲字符串
我跑DotNetOpenAuth,但是當我去驗證,我的網頁呈現字符串
DotNetOpenAuth.Messaging.OutgoingWebResponseActionResult
,而不是認證(這在MVC2應用工作)
我發現這個問題elsewhere on SO,我做了什麼建議,但無濟於事。
這裏是我的web.config
</configSections>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc"
publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="2.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.web.webPages.razor>
還有什麼可以導致此問題的剪輯?
如果有幫助,下面是這是之前MVC3工作控制器代碼
''# <ValidateInput(False)> _ ''# this code is commented out so that it displays properly on StackOverflow - It's not really commented out in the project.
Public Function Authenticate(ByVal go As String) As ActionResult
Dim response As IAuthenticationResponse = openid.GetResponse()
If response Is Nothing Then
''# Stage 2: user submitting Identifier
Dim id As Identifier
If Identifier.TryParse(Request.Form("openid_identifier"), id) Then
Try
Return openid.CreateRequest(Request.Form("openid_identifier")).RedirectingResponse.AsActionResult()
Catch ex As ProtocolException
ViewData("Message") = "Woops! " & ex.Message
Return View("Login")
End Try
Else
ViewData("Message") = "Woops! Invalid identifier"
Return View("Login")
End If
Else
''# Stage 3: OpenID Provider sending assertion response
Select Case response.Status
Case AuthenticationStatus.Authenticated
If Not OpenIDService.IsOpenIdAssociated(response.ClaimedIdentifier) Then
''# All of this happens if the user logging in does
''# not currently have an account associated with
''# their OpenId. We probably want to handle this a
''# little differently by sending them to a view that
''# allows them to confirm account creation or try
''# again.
''# TODO: Create an Authenticate View and a CreateUser ActionResult (without a View)
UserService.AddUser(response.ClaimedIdentifier, response.FriendlyIdentifierForDisplay)
UserService.SubmitChanges()
ActivityLogService.AddActivity(OpenIDService.GetOpenId(response.ClaimedIdentifier).UserID, _
ActivityLog.LogType.UserAdded, _
HttpContext.Request.UserHostAddress)
Else
ActivityLogService.AddActivity(OpenIDService.GetOpenId(response.ClaimedIdentifier).UserID, _
ActivityLog.LogType.UserLogin, _
HttpContext.Request.UserHostAddress)
End If
''# Again, we want to make sure to associate the users
''# actions with an entry in the ActivityLog for further
''# use with Badges
ActivityLogService.SubmitChanges()
''# Create the authentication cookie. This cookie
''# includes the AuthUserData information in the
''# userData field of the FormsAuthentication Cookie.
Dim authUser As Authentication.AuthUserData = New Authentication.AuthUserData(OpenIDService.GetOpenId(response.ClaimedIdentifier).User)
HttpContext.Response.Cookies.Add(Authentication.CustomAuthentication.CreateAuthCookie(response.ClaimedIdentifier, _
authUser, _
True))
authUser = Nothing
If Not String.IsNullOrEmpty(go) Then : Return Redirect(go)
Else : Return RedirectToAction("Index", "Events")
End If
Case AuthenticationStatus.Canceled
ViewData("Message") = "Canceled at provider"
Return View("Login")
Case AuthenticationStatus.Failed
ViewData("Message") = response.Exception.Message
Return View("Login")
End Select
End If
Return New EmptyResult()
End Function
您可能希望升級到最新的DotNetOpenAuth,因爲目前的版本是v3.4.5,但它不會「解決」這個問題。 DotNetOpenAuth針對MVC 1.0進行編譯,以便它適用於較早的安裝。綁定重定向在這裏是正確的解決方案。 – 2010-11-13 22:31:11
謝謝你謝謝你!這在一段時間裏困擾着我。把這個添加到我的web.config中有訣竅。 – 2011-10-18 01:09:41