c++,传递参数的语法
此代码片段是用托管 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
CString::Replace
方法将要替换的字符串和要放置的字符串作为参数。s.Replace( "foo", "bar" )
会将“tadafoo”转换为“tadabar”。现在您的代码将用“/test.aspx?urlString”替换“anystring”。字面上地。
我的猜测是,您希望将 url 作为 GET 参数附加到“/text.aspx”url,在这种情况下您可以执行以下操作:
这将组成 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:
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.您的问题行
是尝试将整个 urlString 替换为 "/test.aspx?urlString" 。
为了实现这一点,你不能将其替换为以下内容吗?
Your problem line of
is trying to replace the entire urlString with "/test.aspx?urlString" .
To achieve this can't you just replace it with the following?
根据您在其他答案中的评论,听起来您想要:
Based on your comments in the other answers, it sounds like you want: