Reputation: 4174
I have an HTTP Handler that requires access to session state. After reading some other questions on SO, I discovered that I needed to add IReadOnlySessionState
to my handler in order to get session state. I did that, and now I can see in my IHttpHandler.ProcessRequest()
that context.Session
has a value.
This is good, but the problem is now context.Request.HttpMethod
is always a GET
. If I remove IReadOnlySessionState, context.Request.HttpMethod
is POST
which is what I expect. So somehow adding IReadOnlySessionState
has caused it to change my HttpMethod
to GET
, and I don't know why.
My code looks something like this:
public class MyHttpHandler : IHttpHandler, IReadOnlySessionState
{
bool IHttpHandler.IsReusable
{
get { return true; }
}
void IHttpHandler.ProcessRequest(HttpContext context)
{
try
{
switch (context.Request.HttpMethod)
{
case "GET":
HandleGet(context);
break;
case "POST":
HandlePost(context);
break;
case "PUT":
HandlePut(context);
break;
case "DELETE":
HandleDelete(context);
break;
default:
break;
}
}
catch (Exception ex)
{
// Do something useful here
}
}
}
I'm invoking the handler using WinHttp in C++:
HINTERNET hRequest = WinHttpOpenRequest(hConnection, _T("POST"), webServicePath, NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_REFRESH);
BOOL rc = WinHttpSendRequest(hRequest, _T("Content-Type: application/x-www-form-urlencoded"), -1, (LPVOID)content, reqLen, reqLen, NULL);
Passing "POST" to WinHttpOpenRequest()
as the method, then sending the request with WinHttpSendRequest()
Upvotes: 2
Views: 471
Reputation: 4174
I fixed it, but I'd still like an explanation if anyone can help - I had <sessionState cookieless="true"/>
in my web.config
. When I changed that to false
, my request came through as a POST. Can anybody explain why?
Upvotes: 1
Reputation: 34846
IRequireSessionState
will work with POST requests, like this:
public class MyHttpHandler : IHttpHandler, IRequireSessionState
Read IRequiresSessionState Interface for documentation.
Upvotes: 2