c++,传递参数的语法

发布于 2024-08-03 04:41:42 字数 1453 浏览 6 评论 0原文

此代码片段是用托管 C++ 编写的 isapi 重定向过滤器的一部分,该过滤器将捕获前缀为“http://test/。一旦捕获了 url,它会将这些请求重定向到我的 web 应用程序根目录下的 test.aspx 文件,

我需要一些语法帮助如何:

1)传递“urlString”参数以显示在我的“中”。 test.aspx”页面。问题行: urlString.Replace(urlString, "/test.aspx?urlString");

2) 我的 aspx 页面显示 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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

伏妖词 2024-08-10 04:41:42

CString::Replace 方法将要替换的字符串和要放置的字符串作为参数。 s.Replace( "foo", "bar" ) 会将“tadafoo”转换为“tadabar”。

现在您的代码将用“/test.aspx?urlString”替换“anystring”。字面上地。

我的猜测是,您希望将 url 作为 GET 参数附加到“/text.aspx”url,在这种情况下您可以执行以下操作:

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

这将组成 url“/test.aspx?urlString=http://test/somethingelse.html":带有名为“urlString”的变量(包含原始网址)的 GET 请求。

您的 asp 应该使用 request.QueryString[ "urlString" ] 读取 GET urlString 变量,使其成为 在这个网站上阅读,否则看起来很好,但我不太喜欢那个。

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.

执笏见 2024-08-10 04:41:42

您的问题行

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

是尝试将整个 urlString 替换为 "/test.aspx?urlString" 。

为了实现这一点,你不能将其替换为以下内容吗?

urlString = "/test.aspx?urlString";

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";
鹤仙姿 2024-08-10 04:41:42

根据您在其他答案中的评论,听起来您想要:

CString newurl = "/test.aspx?UrlString=";
newurl += urlString;

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

CString newurl = "/test.aspx?UrlString=";
newurl += urlString;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文