Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
I have a WebApi based back end (.NET) that will issue the standard Forms Based Authentication (FBA) ticket upon successful login. I am calling my service from an HttpWebRequest. This all works as expected. On receiving the JSON response, I intercept the .ASPXAUTH cookie and save it for later use. My application is a hybrid UIWebView & native.
When making subsequent request to the server to get plain HTML, I use NSHttpCookieStorage to set the cookie. I have found this:
authCookie = new NSHttpCookie(ApplicationContext.AuthenticationCookie);
Does not work. (The ApplicationContext.AuthenticationCookie is the System.Net.Cookie that I saved when the user successfully logged in). However, if I change it to this:
authCookie = new NSHttpCookie(".ASPXAUTH", ApplicationContext.AuthenticationCookie.Value, "/", ".collectedit.com");
It works. I did double check that the Name and the Domain of the System.Net.Cookie matched. Believe me, this threw me for a bit. It appears that something in the returned auth cookie is making it so that the cookie is not treated the same way.
weird, can you give me a value of `ApplicationContext.AuthenticationCookie` that shows the behavior ? I'll be able to check if there's anything internal that differs from the 2 ctors based on this information. Thanks.
There's two main difference between the cookies.
1. `HttpOnly` cannot be set (but that should not affect the client app) and;
2. an empty "" Port (in .NET) creates one entry in PortList (instead of being empty) with a "0" value.
Looking into #2...
Created attachment 1890 [details]
Attached is a fixed copy of monotouch.dll that does not create an empty PathList entry when convertie a .NET cookie to a NSHttpCookie. I would be grateful if you could try this and confirm if it fix your issue.
To use the attached assembly (on top of MonoTouch 5.2.11) do:
1) backup your /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll and /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll.mdb files
2) copy the attached file to /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll
3) remove the /Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll.mdb symbols (they won't match anymore)
4) clean, rebuild and test your application
Tested the following:
1) original monotouch.dll explicitly setting the cookie works
2) original monotouch.dll using the .net version of cookie fails
3) attached monotouch.dll using the .net version of the cookie works
By "works" I mean that I was also looking at my IIS logs that also included logging cookie values. I could see the .ASPXAUTH cookie making it in trials 1 & 3, but not in 2. So I think you've fixed it.
I have to fix something in my code, but this should now allow me to have authenticated web pages in UIWebView *and also* authenticated raw JSON calls using the same mechanism. For anyone using [Authenticated] on the MVC controllers, this is gold Jerry, gold.
I assume that I should revert my patch and wait for the proper release cycle...
Thanks for confirming. We started the cycle for 5.2.12 but I'll look if it's not too late (tags are not done) to include it in the upcoming beta.
QA: a unit test was added in both branch
James: Thanks for testing, I'll let you know asap for 5.2.12 status (in the meantime you can keep the hotfix on top of 5.2.11).
Excellent. Thanks Sebastien.