2010-07-21 27 views

回答

1

我不知道这是否是一个记录的功能,但我会建议以下为jumping-客点:

如果你的代码看起来什么都像我一样,你有一行代码,看起来像:

FederatedPassiveSecurityTokenServiceOperations.ProcessSignInResponse(responseMessage, HttpContext.Current.Response) 

的第二个参数是ProcesssignInResponse HttpResponse对象。我试过了,没有成功,找到一个回答你的问题,试图在自定义HttpResponse消息传递,以捕获输出,所以我们可以操纵它,只要你喜欢:

Dim myStringbuilder As New StringBuilder 
Dim myStringWriter As New IO.StringWriter(myStringbuilder) 
Dim myResponse As New Web.HttpResponse(myStringWriter) 

如果您在myResponse传递给ProcessSignInResponse,引发以下例外:

System.NullReferenceException:未将对象引用设置为对象的实例。用C 在System.Web.HttpResponse.End() 在Microsoft.IdentityModel.Web.FederatedPassiveSecurityTokenServiceOperations.ProcessSignInResponse(SignInResponseMessage signInResponseMessage,HttpResponse对象的HttpResponse) 在Logon_App.LCLoginBase.issueTokenAndRedirect(logonParamsStruct & logonParams):\登录应用\登录应用\代码\ LCLogin \ LCLoginBase.vb:XXX行

+0

这确实看起来像一个非常有前途的想法,我会尝试直接写信给自己,然后再将它交给WIF。 – 2010-07-27 22:05:19

+0

验证确实可行,但是它会创建无效的HTML,因为写入响应的任何内容都将在由WIF插入的html节点之外,但浏览器仍然可以合理地处理此问题。 – 2010-08-16 21:37:00

2

我阅读下面的文章,http://www.paraesthesia.com/archive/2011/01/31.aspx,这使我对Microsoft.IdentityModel装配使用dotPeek。这让我发现,所有ProcessSignInResponse消息呢,是这样的:

public static void ProcessSignInResponse(SignInResponseMessage signInResponseMessage, HttpResponse httpResponse) 
    { 
     if (signInResponseMessage == null) 
     throw DiagnosticUtil.ExceptionUtil.ThrowHelperArgumentNull("signInResponseMessage"); 
     else if (httpResponse == null) 
     { 
     throw DiagnosticUtil.ExceptionUtil.ThrowHelperArgumentNull("httpResponse"); 
     } 
     else 
     { 
     signInResponseMessage.Write(httpResponse.Output); 
     httpResponse.Flush(); 
     httpResponse.End(); 
     } 
    } 

的signInResponseMessage.Write方法执行以下操作:

public override void Write(TextWriter writer) 
    { 
     if (writer == null) 
     { 
     throw DiagnosticUtil.ExceptionUtil.ThrowHelperArgumentNull("writer"); 
     } 
     else 
     { 
     this.Validate(); 
     writer.Write(this.WriteFormPost()); 
     } 
    } 

正如你所看到的,在本质上,所有的执行,将WriteFormPost的内容写入响应流。

因此,我们正在改变我的“ProcessSignIn”方法以返回要输出的HTML,而不是调用FederatedPassiveSecurityTokenServiceOperations.ProcessSignInResponse

所以,我从这里改变了我的方法主要有:

public static void ProcessSignIn(SignInRequestMessage signInRequest, HttpResponse httpResponse) 
    { 
    FederatedPassiveSecurityTokenServiceOperations.ProcessSignInResponse(signInResponseMessage, httpResponse); 
    } 

要:

public static string ProcessSignIn(SignInRequestMessage signInRequest) 
    { 
    return signInResponseMessage.WriteFormPost(); 
    } 

当然,SignInResponseMessage应该提供只返回“主”内容的清洁方法您希望写入表单文章的内容,但将HTML表单作为字符串获取,至少可以在将结果返回给客户端之前修改结果,更易于使用Response.Write(result)

+1

+1不错的黑客在那里。 – 2011-07-29 12:33:38

相关问题