tags:

views:

225

answers:

3

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>
A: 

Your problem line of

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

is trying to replace the entire urlString with "/test.aspx?urlString" .

To achieve this can't you just replace it with the following?

urlString = "/test.aspx?urlString";
David Archer
i just tested it and am using the following with my .aspx page (vb) to display the url: response.write(request.querystring("UrlString")). no luck, is this correct?
MG
What result did you expect, and what did you actually get?
Kim Gräsman
i want to diplay the url on my .aspx page but my method is obviously incorrect b/c i'm just getting a blank screen. also tried, dim url as String = Request.QueryString("UrlString")response.write(url)
MG
A: 

Based on your comments in the other answers, it sounds like you want:

CString newurl = "/test.aspx?UrlString=";
newurl += urlString;
Steve Beedie
Thanks but this method doesn't apply the redirect to my test.aspx page.
MG
+1  A: 

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.

xtofl
this worked, followed by line of code below.urlString.Replace(urlString, newurl);
MG
nice! But if you `Replace` `urlString` as a whole by `newurl`, why not just _use_ `newurl` instead? No need for the complex replacement call at all.
xtofl