Web用户控制和使用会话,请求和响应 [英] Web User Control and using session, request and response

查看:45
本文介绍了Web用户控制和使用会话,请求和响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我正在忙着编写一个新的asp.net应用程序,我正在重用我的一些现有的asp函数和方法。用户控制。我需要访问

会话,在某些功能中请求和响应,我无法找到

如何做到这一点。这是我做的一个例子,我得到以下内容


不能从共享方法中引用类的实例成员或

共享成员没有明确的类实例的初始化程序

此行上的


client = Request.ServerVariables(" HTTP_USER_AGENT")

公共共享功能GetIEVersion()As Double

Dim IEVer,client,ver

client = Request.ServerVariables(" HTTP_USER_AGENT")


如果InStr(1,客户端,MSIE,1)> 0然后

IEVer =拆分(客户端," ;;",-1,1)

ver =拆分(修剪(IEVer(1)),"" ;)(1)

否则

ver = -9999

结束如果

返回ver

结束功能


如果我能找到如何包含像经典ASP这样的文件,那么它也会为我提供


#include file =" inc\utils.asp"在asp =?在asp.net


问候,

乔治

Hi there,

I am busy writing a new asp.net application and I am reusing some of my
existing asp functions and methods in a user control. I need access to
session, request and response in some of the functions and I can''t find out
how to do it. Here is an example of what I do and I get the following

Cannot refer to an instance member of a class from within a shared method or
shared member initializer without an explicit instance of the class

on this line
client = Request.ServerVariables("HTTP_USER_AGENT")
Public Shared Function GetIEVersion() As Double
Dim IEVer, client, ver
client = Request.ServerVariables("HTTP_USER_AGENT")

If InStr(1, client, "MSIE", 1) > 0 Then
IEVer = Split(client, ";", -1, 1)
ver = Split(Trim(IEVer(1)), " ")(1)
Else
ver = -9999
End If
Return ver
End Function

if I can find out how to include files like in classic ASP it would also do
it for me.
#include file = "inc\utils.asp" in asp = ? in asp.net

Regards,
George

推荐答案

嗨乔治:


使用HttpContext.Current,它可以让你访问带有请求,响应和会话属性的curent

请求上下文。
< br $> b $ b -

Scott
http ://www.OdeToCode.com/

On Thu,2004年9月30日11:14:06 +0200,George G.

< george.g @ - xx--buildsmart.co.za>写道:
Hi George:

Use HttpContext.Current, which will give you access to the curent
request context with Request, Response, and Session properties.

--
Scott
http://www.OdeToCode.com/

On Thu, 30 Sep 2004 11:14:06 +0200, "George G."
<george.g@--xx--buildsmart.co.za> wrote:
你好,

我正在忙着编写一个新的asp.net应用程序,我正在重用我现有的一些asp函数和用户控件中的方法。我需要访问
会话,请求和响应某些功能,我无法找到
如何做到这一点。以下是我所做的一个示例,我得到以下内容

不能从共享方法或
共享成员初始化程序中引用类的实例成员而没有类的显式实例

这一行
client = Request.ServerVariables(" HTTP_USER_AGENT")
公共共享功能GetIEVersion()As Double
Dim IEVer,client,ver
client = Request.ServerVariables(" HTTP_USER_AGENT")

如果InStr(1,客户端,MSIE,1)> 0然后
IEVer =拆分(客户端," ;;",-1,1)
ver =拆分(修剪(IEVer(1)),"")(1)
其他
ver = -9999
结束如果
返回ver
结束功能

如果我能找到如何包含像经典ASP这样的文件它我也会这样做。
#include file =" inc\utils.asp"在asp =?在asp.net

问候,
George
Hi there,

I am busy writing a new asp.net application and I am reusing some of my
existing asp functions and methods in a user control. I need access to
session, request and response in some of the functions and I can''t find out
how to do it. Here is an example of what I do and I get the following

Cannot refer to an instance member of a class from within a shared method or
shared member initializer without an explicit instance of the class

on this line
client = Request.ServerVariables("HTTP_USER_AGENT")
Public Shared Function GetIEVersion() As Double
Dim IEVer, client, ver
client = Request.ServerVariables("HTTP_USER_AGENT")

If InStr(1, client, "MSIE", 1) > 0 Then
IEVer = Split(client, ";", -1, 1)
ver = Split(Trim(IEVer(1)), " ")(1)
Else
ver = -9999
End If
Return ver
End Function

if I can find out how to include files like in classic ASP it would also do
it for me.
#include file = "inc\utils.asp" in asp = ? in asp.net

Regards,
George






感谢您的回答。从用户控件访问页面似乎很简单,我应该更多地使用类浏览器。


但是,我还需要更多的帮助。


我尝试从用户控件访问该页面,这样做:

受保护的UC1为UC1 = DirectCast(Page,Parent_Page)

Parent_Page .Label1.Text =" Text here" ''错误在这里


" Label1"在Parent_Page中声明为Public。


这给了我错误对象引用未设置为

对象的实例。在运行时。


然后我尝试设置Label1作为公共共享,现在(它可以,但是)vbc

在编译时给出以下警告:

"警告BC42025:通过实例访问共享成员;

符合条件的表达式将不会被评估。


这里是否与错误和警告消息冲突?错误消息说

我没有使用对象的实例,但是警告消息说我使用

一个实例。


我不明白为什么我需要使用另一个

页面的用户控件实例(或声明类共享)如果用户控件

页面已经在页面中声明了,我从用户控件中引用了

页面。


我在这里想念的是什么?
Thanks for your answers. Accessing page from user controls seemed be
simple, I should use class browser more.

But, I still need more help.

I tried to access the page from a user control, doing it this way:
Protected UC1 As UC1 = DirectCast(Page, Parent_Page)
Parent_Page.Label1.Text = "Text here" '' error here

"Label1" is declared as Public in "Parent_Page".

This gives me error "Object reference not set to an instance of an
object." at the runtime.

Then I tried to set "Label1" as "Public Shared", now (it works, but) vbc
gives me following warning when compiling:
"warning BC42025: Access of shared member through an instance;
qualifying expression will not be evaluated."

Isn''t here conflict with error and warning messages? Error message says
that I don''t use instance of an object, but warning message says I use
an instance.

I don''t understand why I would need to use another instance of the
page′s user control (or declaring class shared) if user controls of the
page are already declared in the page, and I have a reference to the
page from a user control.

What I miss here?


对不起,我可能有点累了。


以前的帖子被认为是继续线程如何访问:a

来自用户控件的页面和另一个用户控件来自另一个用户控件?
Sorry, I maybe a little tired.

Previous post was meaned to be continue to the thread "How to access: a
page from a User control, and another User control from another one?"


这篇关于Web用户控制和使用会话,请求和响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆