« Previous Next »

Thread: Query related to file errors (401 Vs 404)

Last post 04-02-2009 1:58 PM by anilr. 4 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (5 items)

Sort Posts:

  • 03-31-2009, 6:35 AM

    Query related to file errors (401 Vs 404)

    I protected all the URL with the basic auth scheme (I put my code in "OnPostAuthRequest()" method and I successfully accessed the protected resource with the challenge prompt.

    Here my problem is that when I access the page (that is not present) it got an error 404 instead of 401. But when I access the page (that is present) I got basic challege. Here I need the basic challenge in both the cases please anyone tell me what will I do for this.  I need that If the page will not present then after challenge it will display error message 404 (page not found).

    For refrence I have attached the trace file warning that I got. Here I need only the 401 processing & I want to stop the additional prosessing. Please help me to resolve this issue.

    -MODULE_SET_RESPONSE_ERROR_STATUS 

     

    -MODULE_SET_RESPONSE_ERROR_STATUS  IIS Web Core

  • 03-31-2009, 12:53 PM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 6:13 PM
    • Redmond, WA
    • Posts 2,343

    Re: Query related to file errors (401 Vs 404)

    Looks like you still have the anonymous authentication enabled and your authorization rules allow access to the anonymous user - you need to change one of those things to have anonymous requests not go through.

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 04-01-2009, 2:23 AM In reply to

    Re: Query related to file errors (401 Vs 404)

    Thanks for solution :-)

     

  • 04-01-2009, 3:58 AM In reply to

    Re: Query related to file errors (401 Vs 404)

    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;
    }

  • 04-02-2009, 1:58 PM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 6:13 PM
    • Redmond, WA
    • Posts 2,343

    Re: Query related to file errors (401 Vs 404)

    Why are you using OnPostAuthenticate method?  You should use the OnAuthenticate method - otherwise, you will not be able to set the user-context for the user you just authenticated.

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
Page 1 of 1 (5 items)
Microsoft Communities