Thanks a lot :-)
But here I got an error "401.2, Invalid aithentication header" when I disable "Anonymous Authentication" on IIS7 web server. Please tell me the way to disable the "Anonymous Authentication" on "OnPostAutnenticateRequest" because I implement the code related to "Basic authentication" in this method. Please help me to overcome this problem. I have attached the sample (with some changes) that I have used for basic challege (its just sample).
bool
DoBasicChallenge ()
{
string sRealm;
GetBasicAuthRealm (m_httpResponseData.pszRealm, sRealm);
char strAuthtype = new char [1024];
strAuthtype.Printf ( "Basic realm=\"%s\"", sRealm.c_str()))
IHttpResponse * pHttpResponse = m_pContext->GetResponse();
HRESULT hr;
hr = pHttpResponse->SetStatus( 401, "HTTP1.1 401 Unauthorized");
hr = pHttpResponse->SetHeader( "Date", m_tbuf, strlen (tbuf), TRUE);
hr = pHttpResponse->SetHeader( "WWW-Authenticate", strAuthtype, strlen(strAuthtype), TRUE);
hr = pHttpResponse->SetHeader( "Content-type","text/html", strlen ("text/html"),TRUE);
char strResponseBody = "<HTML><HEAD><TITLE>401: Access Denied</TITLE></HEAD><BODY>Access Denied</BODY></HTML>";
HTTP_DATA_CHUNK dataChunk;
dataChunk.DataChunkType = HttpDataChunkFromMemory;
dataChunk.FromMemory.pBuffer = (PVOID) strResponseBody;
dataChunk.FromMemory.BufferLength = strlen(strResponseBody);
DWORD dwMsgLen;
hr = pHttpResponse->WriteEntityChunks(&dataChunk,1,FALSE,TRUE,&dwMsgLen);
return true;
}