关于asp.net中静态成员的问题(C#) [英] Q about static members in asp.net (C#)

查看:66
本文介绍了关于asp.net中静态成员的问题(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我试图阻止人们使用多个浏览器查看我的

页面。


但首先我需要知道静态成员如何一个表单类是

表现。


什么时候是IntanceCounter(见***)desctructet?(重置)当IIS服务器时

是什么歌?然后浏览器关闭?我每次尝试这个都会得到不同的结果。


我有这样的东西:

------- ---------------------

ASPX

----------- -----------------

< form id =" Form1"方法= QUOT;交" runat =" server">

<%Response.Write(WriteHtml()); %>

< / form>


---------------------- ------

codebehind

--------------------------- -

static int Instancecounter = 0; // ***这是instanceCounter


公共字符串WriteHtml()

{

if(counter == 0)

{

Instancecounter ++;

return" HTML to render";

}

其他

{

返回只需要一个浏览器;

}

}

Hi im trying to prevent people from useing more than one browser to view my
page.

But first i need to know excatly how static members of a form class is
behaving.

When is the IntanceCounter (see ***) desctructet?(reset) When the IIS server
is restaret? Then Browser close? Im getting diffrent results everytime i try
this.

I have something like this:
----------------------------
The ASPX
----------------------------
<form id="Form1" method="post" runat="server">
<% Response.Write(WriteHtml()); %>
</form>

----------------------------
codebehind
----------------------------
static int Instancecounter =0; // *** Here is the instanceCounter

public string WriteHtml()
{
if(counter == 0)
{
Instancecounter++;
return "The HTML to render";
}
else
{
return "Only one browser please";
}
}

推荐答案

确定连接到您的网络服务器的用户的当前活动数量(b $ b)通常是非常不同的,除非你的用户在退出之前总是从你的网站上签出
签收,并且你知道'不是
总是如此。


当用户关闭浏览器时,它不会通知网络服务器。

你可以使用javascript触发回发到网络服务器

页面卸载但是,它并不总是有效。当用户终止Internet Explorer时,一个例子是

。任务过程

经理。


从您的代码示例中,IntanceCounter和字段在类的所有

对象之间共享,因此在ASP.NET

工作进程重新启动之前不会重置。


有间接方法限制只有一台浏览器访问每台机器的

网站。但是,如果您能解释为什么要这样做,将会很有帮助。


Web服务器旨在提供大量请求

同时,它通过在处理请求后立即从

客户端释放连接来实现这一点,这就是为什么它非常好

很难执行你正在寻找的功能。


Tommy,


" Flare" <无>在消息新闻中写道:<#3 ************** @ TK2MSFTNGP12.phx.gbl> ...
It is generally very different to determine the current active number
of user connected to your web server, unless your users will always
signoff from you website before they exit, and you know that''s not
always the case.

When a user close their browser, it does not inform the web server.
You could use javascript to trigger a postback to the web server when
the page unloads, however, it will not always work. One example is
when the user terminate the "Internet Explorer" process in task
manager.

From you code sample, the "IntanceCounter" field is shared among all
objects of the class, so it will not get reset until the ASP.NET
worker process restarts.

There are indirect ways to limit only one browser accessing your
website per machine. However, it will be helpful if you could explain
why you would want to do that.

A web server is designed to serve large amount of requests
simultaneously, and it does this by release the connection from the
client as soon as the request is processed, and that is why it is very
difficult to perform the functionality you''re looking for.

Tommy,

"Flare" <None> wrote in message news:<#3**************@TK2MSFTNGP12.phx.gbl>...
您好我试图阻止人们使用更多比一个浏览器查看我的页面。

但首先我需要知道表格类的静态成员是如何表现的。

是IntanceCounter(见***)desctructet?(重置)当IIS服务器
是restaret?然后浏览器关闭?我每次尝试都会得到不同的结果。

我有类似的东西:
------------------- ---------
ASPX
----------------------------
< form id =" Form1"方法= QUOT;交" runat =" server">
<%Response.Write(WriteHtml()); %>
< / form>

----------------------------
codebehind
----------------------------
static int Instancecounter = 0; // ***这是instanceCounter

公共字符串WriteHtml()
{
if(counter == 0)
{
Instancecounter ++;
return"要呈现的HTML;
}

{
返回只需要一个浏览器;
}
}
Hi im trying to prevent people from useing more than one browser to view my
page.

But first i need to know excatly how static members of a form class is
behaving.

When is the IntanceCounter (see ***) desctructet?(reset) When the IIS server
is restaret? Then Browser close? Im getting diffrent results everytime i try
this.

I have something like this:
----------------------------
The ASPX
----------------------------
<form id="Form1" method="post" runat="server">
<% Response.Write(WriteHtml()); %>
</form>

----------------------------
codebehind
----------------------------
static int Instancecounter =0; // *** Here is the instanceCounter

public string WriteHtml()
{
if(counter == 0)
{
Instancecounter++;
return "The HTML to render";
}
else
{
return "Only one browser please";
}
}



>从您的代码示例,IntanceCounter和字段在类的所有
> From you code sample, the "IntanceCounter" field is shared among all
对象之间共享,因此在ASP.NET
工作进程重新启动之前不会重置。


好​​的。我忘记了这个想法。

有间接方法限制每台机器只访问一个浏览器访问你的
网站。但是,如果您能解释为什么要这样做会很有帮助。
objects of the class, so it will not get reset until the ASP.NET
worker process restarts.
Ok. I forget that idea.
There are indirect ways to limit only one browser accessing your
website per machine. However, it will be helpful if you could explain
why you would want to do that.




因为公司里的某些人使用了会话密钥来跟踪servel

导航信息和其他intance specfic detalis。因此当用户打开另一个窗口时,他突然操作同一个sesison对象来自

2个位置。这当然会给出bizrar结果。这就是为什么我想要一种方式来支付
每个只允许一个浏览器。用户/会话。


除了微小的变化之外,没有办法解决除了代码之外的任何问题吗?

sugestions?


Anders



Because some guy in the company has used session keys to track servel
navigation infomation and other "intance" specfic detalis. So when the user
open another window he suddenly os manipulation the same sesison object from
2 places. This of course gives bizrar results. Thats why i want a way to
permit only one browser per. user / session.

There is no way of chaning excisting code other than minor changes,,,any
sugestions?

Anders


Hi Flare,


感谢您发布到MSDN新闻组。


我对这个问题感兴趣,现在正在研究它。我会尽快给你更新



祝你好运,


Jacob Yang

Microsoft在线合作伙伴支持

安全! - www.microsoft.com/security

发布是按原样提供的。没有保证,也没有赋予任何权利。

Hi Flare,

Thank you for posting to the MSDN newsgroups.

I am interested in this issue and researching on it now. I will update you
as soon as possible.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


这篇关于关于asp.net中静态成员的问题(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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