从 ASPX 调用经典 ASP 函数
Call classic ASP function from ASPX
我正在开发一个 旧 网络应用程序,其中的页面是用 classic ASP
编写的,并使用 Iframes
包装在 aspx
个页面中。我正在重写 ASP.NET
中的其中一个页面(使用 C#),完全删除对 iframe 的依赖。 page_to_rewrite.asp
调用同一应用程序中其他 ASP 页面中存在的许多其他函数。
我在从 aspx.cs 调用那些 ASP 函数时遇到困难。我尝试像这样使用 WebClient class:
using (WebClient wc = new WebClient())
{
Stream _stream= wc.OpenRead("http://localhost/Employee/finance_util.asp?function=GetSalary?EmpId=12345");
StreamReader sr= new StreamReader(_stream);
string s = sr.ReadToEnd();
_stream.Close();
sr.Close();
}
使用 IIS HTTP 模块检查到达此应用程序的每个请求是否存在有效的会话 cookie,如果不存在,则将用户重定向到登录页面。现在,当我从 aspx 调用此 ASP 页面 url 时,我得到我的应用程序的登录页面作为响应,因为不存在会话 cookie。
任何人都可以请建议我如何才能成功调用 ASP 方法。
正如@Schadensbegrenzer 在评论中所说,我只需要像这样在请求中传递 cookie header:
using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.Cookie] = "SessionID=" + Request.Cookies["SessionID"].Value;
Stream _stream= wc.OpenRead("http://localhost/Employee/finance_util.asp?function=GetSalary&EmpId=12345");
StreamReader sr= new StreamReader(_stream);
string s = sr.ReadToEnd();
_stream.Close();
sr.Close();
}
在 Whosebug 上的其他类似问题中,一些人建议在请求 header 中也包含 User-Agent
如果您从 asp 页面获得空白输出,因为某些 Web 服务器需要请求中的此值 headers。看看它是否对您的情况有帮助。我的即使没有它也能工作。
此外,您还必须像这样处理 ASP page
中的请求:
Dim param_1
Dim param_2
Dim output
param_1 = Request.QueryString("function")
param_2 = Request.QueryString("EmpId")
If param_1 = "GetSalary" Then
output = GetSalary(param_2)
response.write output
End If
希望对您有所帮助!
我正在开发一个 旧 网络应用程序,其中的页面是用 classic ASP
编写的,并使用 Iframes
包装在 aspx
个页面中。我正在重写 ASP.NET
中的其中一个页面(使用 C#),完全删除对 iframe 的依赖。 page_to_rewrite.asp
调用同一应用程序中其他 ASP 页面中存在的许多其他函数。
我在从 aspx.cs 调用那些 ASP 函数时遇到困难。我尝试像这样使用 WebClient class:
using (WebClient wc = new WebClient())
{
Stream _stream= wc.OpenRead("http://localhost/Employee/finance_util.asp?function=GetSalary?EmpId=12345");
StreamReader sr= new StreamReader(_stream);
string s = sr.ReadToEnd();
_stream.Close();
sr.Close();
}
使用 IIS HTTP 模块检查到达此应用程序的每个请求是否存在有效的会话 cookie,如果不存在,则将用户重定向到登录页面。现在,当我从 aspx 调用此 ASP 页面 url 时,我得到我的应用程序的登录页面作为响应,因为不存在会话 cookie。
任何人都可以请建议我如何才能成功调用 ASP 方法。
正如@Schadensbegrenzer 在评论中所说,我只需要像这样在请求中传递 cookie header:
using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.Cookie] = "SessionID=" + Request.Cookies["SessionID"].Value;
Stream _stream= wc.OpenRead("http://localhost/Employee/finance_util.asp?function=GetSalary&EmpId=12345");
StreamReader sr= new StreamReader(_stream);
string s = sr.ReadToEnd();
_stream.Close();
sr.Close();
}
在 Whosebug 上的其他类似问题中,一些人建议在请求 header 中也包含 User-Agent
如果您从 asp 页面获得空白输出,因为某些 Web 服务器需要请求中的此值 headers。看看它是否对您的情况有帮助。我的即使没有它也能工作。
此外,您还必须像这样处理 ASP page
中的请求:
Dim param_1
Dim param_2
Dim output
param_1 = Request.QueryString("function")
param_2 = Request.QueryString("EmpId")
If param_1 = "GetSalary" Then
output = GetSalary(param_2)
response.write output
End If
希望对您有所帮助!