SAML 2.0 to Salesforce: OutputStream is not available when a custom TextWriter is used.

Its an ASP.NET MVC 3 application with SSO/LogIn as the controller/action. I’m using the sample code provided in the example directory.

The StackTrace is :
at System.Web.HttpResponse.get_OutputStream() at System.Web.HttpResponseWrapper.get_OutputStream() at ComponentSpace.SAML2.InternalSAMLIdentityProvider.SendSAMLResponse(HttpResponseBase httpResponse, XmlElement samlResponseElement, String relayState, String binding, String assertionConsumerServiceUrl) in C:\Sandboxes\ComponentSpace\SAMLv20\Library\InternalSAMLIdentityProvider.cs:line 562 at ComponentSpace.SAML2.InternalSAMLIdentityProvider.InitiateSSO(HttpResponseBase httpResponse, String userName, SAMLAttribute[] attributes, String relayState, String partnerSP, String assertionConsumerServiceUrl) in C:\Sandboxes\ComponentSpace\SAMLv20\Library\InternalSAMLIdentityProvider.cs:line 703 at ComponentSpace.SAML2.SAMLIdentityProvider.InitiateSSO(HttpResponseBase httpResponse, String userName, IDictionary attributes, String relayState, String partnerSP) in C:\Sandboxes\ComponentSpace\SAMLv20\Library\SAMLIdentityProvider.cs:line 190 at Test.Controllers.SSOController.LogIn(String type, String acctNumber)

Any ideas?


Does the MvcExampleIdentityProvider project work for you?
Would you be able to reproduce the issue in a small test project, zip it up excluding any DLLs, and send it to support@componentspace.com?

Hello,

1. Sample Solution works.
2. I created a new project and that works too.
3. In my project solution, it fails where it needs to make an http call to Salesforce. Below is the log that ComponentSpace generates (I have removed the details of SAML Response)

Step into: Stepping over method without symbols ‘System.Web.Mvc.Controller.Response.get’
ComponentSpace.SAML2 Verbose: 0 : 10572/30: 9/29/2015 8:02:48 PM: Initiating SSO to the partner service provider https://saml.salesforce.com.
ComponentSpace.SAML2 Verbose: 0 : 10572/30: 9/29/2015 8:02:48 PM: Identity provider session (s0mzfna5akgtgimwd3zzz1dy) state:
ComponentSpace.SAML2 Verbose: 0 : 10572/30: 9/29/2015 8:02:48 PM: SAML assertion constructed: partner provider=https://saml.salesforce.com,
ComponentSpace.SAML2 Verbose: 0 : 10572/30: 9/29/2015 8:02:48 PM: SAML message ready to send: partner provider=https://saml.salesforce.com,
A first chance exception of type ‘System.Web.HttpException’ occurred in System.Web.dll


But in the new project that I created, it goes through. I compared the SAML response between the two and the structure was identical.
ComponentSpace.SAML2 Verbose: 0 : 16404/183: 9/29/2015 8:40:20 PM: SAML assertion constructed: partner provider=https://saml.salesforce.com
ComponentSpace.SAML2 Verbose: 0 : 16404/183: 9/29/2015 8:40:20 PM: SAML message constructed: partner provider=https://saml.salesforce.com,
ComponentSpace.SAML2 Verbose: 0 : 16404/183: 9/29/2015 8:40:20 PM: SAML message ready to send: partner provider=https://saml.salesforce.com,
ComponentSpace.SAML2 Verbose: 0 : 16404/183: 9/29/2015 8:40:20 PM: Sending response over HTTP POST, targetURL=https://test.salesforce.com?so=xxxxxxxxxxx,
ComponentSpace.SAML2 Verbose: 0 : 16404/183: 9/29/2015 8:40:20 PM: Sending form by HTTP Post:
ComponentSpace.SAML2 Verbose: 0 : 16404/183: 9/29/2015 8:40:20 PM: Sending SAML form:
ComponentSpace.SAML2 Verbose: 0 : 16404/183: 9/29/2015 8:40:20 PM: Response sent over HTTP POST
ComponentSpace.SAML2 Verbose: 0 : 16404/183: 9/29/2015 8:40:20 PM: SAML response sent: partner provider=https://saml.salesforce.com,
ComponentSpace.SAML2 Verbose: 0 : 16404/183: 9/29/2015 8:40:20 PM: Identity provider session (xxxxxxxxxxxxxxxxxxxx) state:
SSO session state:
Partner name: https://saml.salesforce.com
Name ID: <saml:NameID Format=“urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified” xmlns:saml=“urn:oasis:names:tc:SAML:2.0:assertion”>xxxxxxxx</saml:NameID>
Session index: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


It’s hard to say without more information. The original stack trace you provided implies some of the ASP.NET/MVC plumbing isn’t setup. If the example we provide as well as the new project you created both work but your project solution doesn’t you might have to closely compare these to see what the differences are. You’re welcome to zip up a small test project and email it to us so we can try to reproduce the issue.

We were able to resolve the issue. It was breaking because of the Caching Attribute on the Controller. Thanks for your help!!!

I’m glad you resolved the issue and thanks for letting me know.