asp.netc++isapi

c++, syntax for passing parameters


This code snippet is part of an isapi redirect filter written in managed c++ that will capture url requests with prefix "http://test/. Once the url is captured it will redirect those request to a test.aspx file i have at the root of my web app.

I need some syntax help how to:

1) pass the "urlString" parameter to be displayed in my "test.aspx" page. Problem line: urlString.Replace(urlString, "/test.aspx?urlString");

2) syntax for my aspx page to display urlString

   DWORD CRedirectorFilter::OnPreprocHeaders(CHttpFilterContext* pCtxt,
            PHTTP_FILTER_PREPROC_HEADERS pHeaderInfo)
        {
            char buffer[256];
            DWORD buffSize = sizeof(buffer);
            BOOL bHeader = pHeaderInfo->GetHeader(pCtxt->m_pFC, "url", buffer, &buffSize); 
            CString urlString(buffer);
            urlString.MakeLower(); // for this exercise 



            if(urlString.Find("/test/") != -1)  //insert url condition
        {


            urlString.Replace(urlString, "/test.aspx?urlString");


                char * newUrlString= urlString.GetBuffer(urlString.GetLength());
                pHeaderInfo->SetHeader(pCtxt->m_pFC, "url", newUrlString);
                return SF_STATUS_REQ_HANDLED_NOTIFICATION;
            }
        //we want to leave this alone and let IIS handle it
            return SF_STATUS_REQ_NEXT_NOTIFICATION;
        }

-------------- aspx page

<html>
<body>
<%
dim url as string = request.querystring("urlString")
response.write(url)

%>
</body>
</html>

Solution

  • The CString::Replace method takes the string-to-be-replaced and the string-to-be-put-in-place as arguments. s.Replace( "foo", "bar" ) will convert "tadafoo" into "tadabar".

    Now your code will replace "anystring" with "/test.aspx?urlString". Literally.

    My guess is that you want your url to be appended to the "/text.aspx" url as a GET argument, in which case you can do this:

    CString newurl = "/text.aspx?urlString=";
    newurl += urlString; 
    

    This will compose the url "/test.aspx?urlString=http://test/somethingelse.html": a GET request with a variable named "urlString" containing your original url.

    Your asp should read the GET urlString variable with the request.QueryString[ "urlString" ] as to be read on this website, and looks just fine otherwise, But I'm not really into that.