c#写ASP用服务端组件获取request值?

jd_zhangfeng 2009-11-15 09:25:42
小弟最近由于项目需要,要用C#来写一个asp用的组件,遇到不少问题,从中也学习了不少
现在遇到一个难题
先看代码

using System;
using System.Collections.Generic;
using System.Text;
using ASPTypeLibrary;
using Microsoft.VisualBasic;

namespace aspdll
{
public class Class2
{
public Request Myrequest;
public Response Myresponse;



public void OnStartPage(ScriptingContext sc)
{
Myrequest = sc.Request;
Myresponse = sc.Response;
Myresponse.Write(Myrequest.QueryString["test"]);//这里可以直接输出我传入的querstring的值
if (Myrequest.QueryString["zf"] == "abc")

/*但是这里,始终无法验证通过,Myrequest.QuertString是一个IRequestDictionary对象,和string无法比较,
* 但是Myrequest.QueryString["zf"].tostring()返回的值却是System_Com,我如何才能正确的进行判断?*/
{
Myresponse.Write("ok");
Myresponse.Cookies["test"] = "z";//这里也无法通过,因为Cookies只有get没有set
}

}


}

}


这两个问题困扰我已经很长时间了,资料查看了很多,始终没有解决
请高手帮我解答下,谢谢,如果分不够可以再加

...全文
444 43 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
43 条回复
切换为时间正序
请发表友善的回复…
发表回复
jd_zhangfeng 2009-11-16
  • 打赏
  • 举报
回复
呵呵,我比较急性子,VB VC是可以写,但是项目要求C#,因为我接手的时候这个项目已经用了一个C#的控件

MVP 微软给的定义是

微软最有价值专家 (MVP) 是指具备一种或多种微软技术专业知识,并且积极参与在线或离线的社群活动,经常与其他专业人士分享知识和专业技能,受人尊敬、信任,而且平易近人的专家。

实际生活中,人们总是信任专家的建议和反馈。MVP正是这样一群拥有丰富知识和实际经验的微软技术专家。他们不是微软的员工,但是非常乐于通过在线或离线社区的方式帮助技术人士。另一方面,微软公司时刻不忘倾听来自用户的意见反馈,不断开发新产品,改进技术,提高用户体验。MVP代表来自社群的广大用户,他们的专家意见更能协助微软公司了解用户的真实需求。

所以么,嘿嘿。。


C#新学,用着手生,这两天在翻书
发现《C#本质论》这本书不错,好久没啃书了
jd_zhangfeng 2009-11-16
  • 打赏
  • 举报
回复
急啊
  • 打赏
  • 举报
回复
[Quote=引用 40 楼 jd_zhangfeng 的回复:]
引用 39 楼 liuxiaoyi666 的回复:
忽然发现这个人估计也是中国人,难道只有咱们才这么bt么??
不是只有咱们这么BT,而是只有中国这个环境造就了遗留的ASP环境过多,给逼的研究啊,唉
这个方案我一开始尝试过,最终没搞定,给我放弃了,明天到公司再看看是不是当时写的有问题
[/Quote]

你又不是不会写vb6 vc6 直接用那些写多好啊,非常的顺畅....

我刚才看forum.asp.net的那个帖子的时候吓了我一跳,怎么一模一样的代码呢...后来发现是你发的

结帖不用这么急的,我看了一下mvp原来都是答题使的,那个mvp看来也没比我高明....哈哈,笑死我了
jd_zhangfeng 2009-11-16
  • 打赏
  • 举报
回复
不管怎么样了,这帖子先结了,放着好多天了,谢谢各位帮助我的朋友
jd_zhangfeng 2009-11-16
  • 打赏
  • 举报
回复
[Quote=引用 39 楼 liuxiaoyi666 的回复:]
忽然发现这个人估计也是中国人,难道只有咱们才这么bt么??
[/Quote]不是只有咱们这么BT,而是只有中国这个环境造就了遗留的ASP环境过多,给逼的研究啊,唉
这个方案我一开始尝试过,最终没搞定,给我放弃了,明天到公司再看看是不是当时写的有问题
  • 打赏
  • 举报
回复
忽然发现这个人估计也是中国人,难道只有咱们才这么bt么??
  • 打赏
  • 举报
回复
I finally got it to work by using:

IEnumerator oEnum = oServerVariables["SCRIPT_NAME"];
oEnum.MoveNext();
string sScriptName = (string) oEnum.Current;

Shan


这个人的最终解决方案...值么设想的话....估计你也得这么做了,你看明白了不...
  • 打赏
  • 举报
回复
http://forums.asp.net/p/1493164/3514428.aspx

搜索到你的帖子了,哈哈

http://www.dotnet247.com/247reference/msgs/7/38709.aspx

Shan,

The get_Item method is the way the property looks to C++ clients. What
you want to do is call it like a property, either:

sScriptName = (string) oServerVariables.Item("SCRIPT_NAME");

or

sScriptName = (string) oServerVariables.Item["SCRIPT_NAME"];

I don't believe the second one will work, but it is worth a shot. The
reason for this is that I am not sure if the imported interface definition
will treat parameters in a property like indexers or if it should use the
basic function calling convention.

注意这段儿回复....
芽疼 2009-11-16
  • 打赏
  • 举报
回复
没弄过 帮顶
jd_zhangfeng 2009-11-16
  • 打赏
  • 举报
回复
我看了下,不过貌似没什么帮助,system.runtime.interopservices应该是一个如何在。net程序中调用com接口的解决方案
但是现在的问题不是我不能调用接口
而是接口返回的值不是我所要的
这两天我仔细的研究过了asp的com接口
发现这么个问题
我在VB6中写同样的代码,request.quertstring会有个item方法,其返回值是string类型
但是在C#中没有了这个方法,只有个类似的get_item但是他的返回值是一个名为 IRequestDictionary的对象,IRequestDictionary 是 继承自 IEnumerable,我尝试将 request.querystring强制转化为IEnumerable,并且对其做了遍历,但最终任然不能得到我要的结果

下面分别是request和IRequestDictionary 接口定义



using System;
using System.Reflection;
using System.Runtime.InteropServices;

namespace ASPTypeLibrary
{
[Guid("D97A6DA0-A861-11CF-93AE-00A0C90C2BD8")]
[TypeLibType(4176)]
public interface IRequest
{
[DispId(1610743811)]
IRequestDictionary Body { get; }
[DispId(1610743813)]
IRequestDictionary ClientCertificate { get; }
[DispId(1610743814)]
IRequestDictionary Cookies { get; }
[DispId(1610743810)]
IRequestDictionary Form { get; }
[DispId(1610743809)]
IRequestDictionary QueryString { get; }
[DispId(1610743812)]
IRequestDictionary ServerVariables { get; }
[DispId(1610743815)]
int TotalBytes { get; }

[DispId(0)]
object this[string bstrVar] { get; }

[DispId(1610743816)]
object BinaryRead(ref object pvarCountToRead);
}
}







using System;
using System.Collections;
using System.Reflection;
using System.Runtime.InteropServices;

namespace ASPTypeLibrary
{
[Guid("D97A6DA0-A85F-11DF-83AE-00A0C90C2BD8")]
[TypeLibType(4176)]
public interface IRequestDictionary : IEnumerable
{
[DispId(1610743810)]
int Count { get; }

[DispId(0)]
object this[object Var] { get; }

[DispId(1610743811)]
object get_Key(object VarKey);
[DispId(-4)]
[TypeLibFunc(1)]
IEnumerator GetEnumerator();
}
}





jd_zhangfeng 2009-11-16
  • 打赏
  • 举报
回复
有哪位可以帮帮我么?
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/zh-cn/library/system.runtime.interopservices(VS.80).aspx
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/zh-cn/library/system.runtime.interopservices.marshal(VS.80).aspx

尝试一下这个...
jd_zhangfeng 2009-11-16
  • 打赏
  • 举报
回复
那你先忙,我再研究会,谢谢兔子
  • 打赏
  • 举报
回复
System.Runtime.InteropServices 我觉得可以用这个做些文章,不过我现在实在没空了...

http://social.microsoft.com/Forums/zh-CN/Offtopic/thread/ebfb3ad9-c320-4371-b88a-06825ecd61d9

看了这个问题,我到有点转过来了,我刚才用了另外一个测试页不是这个项目的做的测试,貌似是俺看错了....

不好意思
jd_zhangfeng 2009-11-16
  • 打赏
  • 举报
回复
兔子你试下

public void Test()
{
myresponse.Write(myrequest.QueryString["test"]+"<hr>");
if (myrequest.QueryString["test"].ToString() == "abc")
{
myresponse.Write("ok<hr>");
}
myresponse.Write(myrequest.QueryString["test"].ToString()+"<hr>");

}
就能明白我的意思了
  • 打赏
  • 举报
回复
<%
set obj=server.createobject("comdll.testClass")
obj.Test()
%>

这个是asp页面成功显示出来了
  • 打赏
  • 举报
回复
public string ini_dme(string entryuser, string entrypass, string agentname, string agentpass, string constr)
{
return "0";
}

public string ini_svr(string entryuser, string entrypass, string agentname, string agentpass, string constr)
{
return "0";
}


这个没用我忘记删除了
  • 打赏
  • 举报
回复
public void Test()
{
myresponse.Write(myrequest.QueryString["test"]);
if (myrequest.QueryString["test"].ToString() == "abc")
{
myresponse.Write("ok");
}
}

我一开始就说了,单独提出一个函数......不要在onstartpage里写就成了....
jd_zhangfeng 2009-11-16
  • 打赏
  • 举报
回复
我发给你的项目本来就是可以正常在asp中运行的,我虽然没有写interface部分,但是只要在项目属性里面设置为对com可见就完全可以在ASP中直接调用的,我问题的关键是 如何将IRequestDictionary转为string
加载更多回复(23)

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧