2010-11-12 68 views
4

我刚刚更新了我的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 

回答

5

嗯,这似乎已经解决了这个问题......我应该使用不同版本的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> 
+0

您可能希望升级到最新的DotNetOpenAuth,因为目前的版本是v3.4.5,但它不会“解决”这个问题。 DotNetOpenAuth针对MVC 1.0进行编译,以便它适用于较早的安装。绑定重定向在这里是正确的解决方案。 – 2010-11-13 22:31:11

+0

谢谢你谢谢你!这在一段时间里困扰着我。把这个添加到我的web.config中有诀窍。 – 2011-10-18 01:09:41

0

只是建立在追逐的回答,您可以设置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> 
相关问题