I have a Web API project and in the same domain I have another HTML based application. My Web API project uses sessions and that part works fine. From my HTML project, I make requests from an IHttpHandler using:
var handler = new HttpClientHandler();
handler.CookieContainer = CookieContainer;
using (var client = new HttpClient(handler))
{
client.BaseAddress = new Uri(ServerAddress);
var message = client.GetAsync(url);
return message.Result.Content.ReadAsStringAsync().Result;
}
When I use the same CookieContainer it works fine as the session is between the HttpClient and Web API project throught the CookieContainer. My requirement is that I want to access the same session in the IHttpHandler.
What I noticed is that HttpContext.Current.Session in the IHttpHandler is null and if I use the IRequiresSessionState or IReadOnlySessionState, the session is not null but the values in the session are not passed on.
I feel that the session in the CookieContainer is different when compared to the session in the Handler. Is there a way to access the session in the Handler (the one in CookieContainer). Do I need to make a Web Request in a different way?
I also tried the CookieLessSession entry in Web.config and that did not work out well for me. Any thoughts?
Aucun commentaire:
Enregistrer un commentaire