asp.net Web服务器是否按请求运行Web应用程序的新实例? [英] Does an asp.net web-server run a new instance of a web application per request?

查看:36
本文介绍了asp.net Web服务器是否按请求运行Web应用程序的新实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含私有/受保护方法或私有/受保护变量的Web应用程序

I have a web application with private/protected methods or private/protected variables

首先,我想知道某个Web服务器何时已经为某个Web应用程序建立了连接,然后接收到新连接,是否为该新连接运行Web应用程序的新实例,从而重新初始化所有就像在计算机上一样,该Web应用程序中的变量?

First I would like to know when a web-server has a connection established already for a certain web application and then receives a new connection does it run a new instance of the web application for this new connection and thus re-initializing all the variables in that web application just like on a computer?

我已经浏览了互联网,我感到非常困惑!

I have goggled the Internet and I am terribly confused!

第二,我正在使用Visual Studio开发服务器,并且我了解到它不接受来自其他计算机的连接,我已经通过使用端口转发软件解决了这个问题.所以问题是,通过从本地计算机上的应用转发这些请求,VS2010 Web服务器是否会将每个不同的请求视为新请求还是相同请求?

Second I am using the visual studio development server and I have learned that it doesn't accept connections from other computers, I have gotten around this by using a port forwarding software. So the question is, By doing this does VS2010 web-server see each different requests as a new request or same request since am forwarding them from an app on the local computer?

最后,如果我在一个浏览器上打开了Web应用程序,然后决定在另一个浏览器上打开它并保持当前浏览器处于打开状态,那么这会被视为新请求还是回发?

Finally if I have a web application open on one browser and then decide to open it on another browser and keep the current browser open is this treated as a new request or a post-back?

推荐答案

应用程序域是恒定的(可以回收),并且仅在第一个请求上创建(也可以在此之前设置).

The app domain is constant (can be recycled) and is created only on the first request (also can be set before that).

也就是说,所有静态变量仅初始化一次但您的请求所依赖的所有非静态类都会在每个请求上初始化.

That is to say all the static variables are initialized only once but all the not static classes on which your request depends are initialized on every request.

因此,基本上,每个请求都会初始化普通asp.net中的所有页面以及asp.net MVC中的所有控制器.

So basically all your pages in normal asp.net and all the controllers in asp.net MVC are initialized on every request.

在此处了解更多信息 http://www.codeproject.com/Articles/73728/ASP-NET-Application-and-Page-Life-Cycle

*注意-图片取自上述文章

*note - the image has been take from the article referred above

这篇关于asp.net Web服务器是否按请求运行Web应用程序的新实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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