【问题标题】:ASP.NET MVC3 - ActionResult rendering DotNetOpenAuth WebResponse as StringASP.NET MVC3 - ActionResult 将 DotNetOpenAuth WebResponse 呈现为字符串
【发布时间】:2011-05-08 21:42:09
【问题描述】:

我刚刚更新了我的 MVC2 项目以运行 MVC3 (RC)。除了一个问题,一切都按预期工作。

我正在运行 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

【问题讨论】:

    标签: asp.net dotnetopenauth asp.net-mvc-3


    【解决方案1】:

    这似乎已经解决了问题...我应该使用不同版本的 DotNetOpenAuth 吗?我当前的版本是 [Version - 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>
    

    【讨论】:

    • 您可能想要升级到最新的 DotNetOpenAuth,因为当前版本是 v3.4.5,但它不会“解决”这个问题。 DotNetOpenAuth 针对 MVC 1.0 进行编译,因此它适用于较旧的安装。绑定重定向是正确的解决方法。
    • 谢谢谢谢!这困扰了我很长一段时间。将此添加到我的 web.config 中就可以了。
    【解决方案2】:

    只是为了建立在追逐的答案上,您可以将 oldVersion 设置为一个范围,从而节省您多次编写它

    </configSections>
        <runtime>
            <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
                <dependentAssembly>
                    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
                    <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> 
                </dependentAssembly>
            </assemblyBinding>
        </runtime>
    <system.web.webPages.razor>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-10
      相关资源
      最近更新 更多