我刚刚更新了我的 MVC2 项目以运行 MVC3 (RC)。除了一个问题外,一切都按预期工作。
我正在运行 DotNetOpenAuth,但是当我进行身份验证时,我的页面会呈现字符串
而不是身份验证(在 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 之前工作的 Controller 代码
''# <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 吗?我当前的版本是 [版本 - 3.4.3.10143]
</configSections>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc"
publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0" newVersion="3.0.0.0"/>
<bindingRedirect oldVersion="2.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.web.webPages.razor>
关于ASP.NET MVC3 - ActionResult 将 DotNetOpenAuth WebResponse 呈现为字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4162063/