I have 2 web applications.
The first web application contains ASP.NET web pages and used a Membership provider for authentication.
The second web application is strictly an OData WEB API site that requires authentication.
Both sites have the same “machineKey validationKey / decryptionKey” in the web config and both are using “Forms” authentication with the same “forms name of .TESTAUTH”
When I call the OData service and inspect the IDentity for both the thread and httpcontext they are both empty for the name and isauthenticated.
So how do I get the OData to recognize the .TESTAUTH cookie?
EDIT:
Well here is what I did. It doesn’t seem right but if someone knows a better way please let me know.
dbContext.BuildingRequest += AddCookie;
private void AddCookie(object sender, Microsoft.OData.Client.BuildingRequestEventArgs e)
{
var authCookie = HttpContext.Current.Request.Cookies(".TESTAUTH");
e.Headers.Add("Cookie", ".TESTAUTH=" + authCookie.Value);
}
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Here is what I did to solve the problem.
dbContext.BuildingRequest += AddCookie;
private void AddCookie(object sender, Microsoft.OData.Client.BuildingRequestEventArgs e)
{
var authCookie = HttpContext.Current.Request.Cookies(".TESTAUTH");
e.Headers.Add("Cookie", ".TESTAUTH=" + authCookie.Value);
}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0