10
This is a question that I have always had (including in previous versions of ASP.NET), but I will ask here in the context of ASP.NET 5. The question is this: when building an application with ASP.NET 5 we encode a class Startup
who is responsible for setting up the pipeline with a method Configure
. Anything related to web application startup is done there.
That is exactly where my doubt lies: the concept of initialization of the web application. A web application does nothing for itself, it expects requests to do. The question is: made a request the application is initialized, receives the request, sends the reply and finishes? Or it initializes if not, processes the request, responds and waits for new requests?
How does this startup concept work for an ASP.NET 5 web application? If it really starts if you’re not and you’re waiting for new requests, how does it really work?
I did a test to see if I understood better what is happening as follows: I created a Singleton class Exemplo
who owns a property DataInstanciado
. After that I created a controller ExemploController
as follows:
public class ExemploController : Controller
{
[HttpGet("/api/instancia")]
public Exemplo GetInstancia()
{
return Exemplo.ObtemInstancia();
}
}
When sending a request for "/api/instance" I received an object containing a datetime which is the date of the creation of the object. In later requests the returned object was exactly the same, with the same date. After 30 minutes, when requesting the returned object again, it was another, with the date 30 minutes later.
This way, the server seems to be keeping the application running. It seems that the objects remain in memory. But I don’t understand how this works. How the life cycle of this type of application works?
EDITION: I know there’s a life cycle of an application running on IIS, but it’s not specifically IIS I’m asking about. ASP.NET 5 applications use the OWIN specification and can therefore be hosted not only on IIS, but in other ways as well (such as self host). What I wanted to know is how the life cycle works, regardless of where the application is hosted.
I believe this is the server session time and not Asp.net Lifecycle.
– Jhonathan
I really thought it had something to do with session, so to test put in the controller before Return the line
this.Context.Session.Clear()
and then I started getting the error "Invalidoperationexception: Session has not been configured for this application or request." so that apparently the use of sessions is not even set by default.– SomeDeveloper
see if this helps https://msdn.microsoft.com/en-us/library/bb470252(v=vs.140). aspx
– kabstergo
@kabstergo, it helps a little, but that’s in relation to the OSI specifically. ASP.NET 5 uses the OWIN specification, hence the lifecycle should not be connected directly to the server. You know if you have something similar for ASP.NET 5?
– SomeDeveloper