some questions about asp.net

  • Thread starter Thread starter Servé Lau
  • Start date Start date
S

Servé Lau

I have been rewriting a C++ isapi into a C# asp.net application, but because
it was my first one and created within a tight schedule I have some
questions to make sure if I did it right.

1. Does asp.net create a new instance of the Page class for every request?

2.
I created a class for the settings of the application, meaning that I have
static instance holding a reference to the settings object. I'd say that
this will store one object for all users (or at least I hope so) Can I do
this or will static class members get removed when a client's session
expires?

example:
public class App : System.Web.UI.Page
{
private static SomeClass data; // do I have server side status now?
private void Page_Load(object sender, System.EventArgs e) { if (data ==
null) data = new SomeClass(); }
}

3.
the Page_Load is executed every time a request is done. What I have done is
call my main function in Page_Load, this function fills up a string member
variable. I have overridden Page.Render to write that string to the output.
Is this the correct way or is iot better to just use Page.Response.Write
like in asp?

4.
Can I change the content-type as much as I want or can I do this only once
in Render?

5.
The machine.config file holds information about worker threads and IO
threads per cpu and the request queue length.
What's the difference between a worker thread and IO thread here?
Does every thread have a request queue or is there only one?

6.
I think I know the answer to this one already but I'll ask anyway. Is
asp.net implemented that it takes threads from the global IIS thread pool or
does it implement its own pool and hands out threads from that one?

Thanks for reading if you've come this far :-)
 
Comments inline:

Servé Lau said:
I have been rewriting a C++ isapi into a C# asp.net application, but because
it was my first one and created within a tight schedule I have some
questions to make sure if I did it right.

1. Does asp.net create a new instance of the Page class for every request?

Yes. As HTTP is stateless, the Page class must be re-created with each
Request.
2.
I created a class for the settings of the application, meaning that I have
static instance holding a reference to the settings object. I'd say that
this will store one object for all users (or at least I hope so) Can I do
this or will static class members get removed when a client's session
expires?

example:
public class App : System.Web.UI.Page
{
private static SomeClass data; // do I have server side status now?
private void Page_Load(object sender, System.EventArgs e) { if (data ==
null) data = new SomeClass(); }
}

Static objects exist in the heap, which means that they live for the
lifetime of the web application.
3.
the Page_Load is executed every time a request is done. What I have done is
call my main function in Page_Load, this function fills up a string member
variable. I have overridden Page.Render to write that string to the output.
Is this the correct way or is iot better to just use Page.Response.Write
like in asp?

Neither. ASP.Net is object-oriented, and Response.Write is procedural.
Depending upon what this string is, and what function it serves, you might
want to put it into a Label, Placeholder, Web User Control, or some other
container class for HTML.
4.
Can I change the content-type as much as I want or can I do this only once
in Render?

How many ContentTypes do you think one Response can have? (Answer: one)
5.
The machine.config file holds information about worker threads and IO
threads per cpu and the request queue length.
What's the difference between a worker thread and IO thread here?
Does every thread have a request queue or is there only one?

??? I don't understand what you're trying to get at here. There is only one
Request Queue, and it is managed by IIS. It is used to queue HTTP requests
that arrive while there are no avialable threads to process them.
6.
I think I know the answer to this one already but I'll ask anyway. Is
asp.net implemented that it takes threads from the global IIS thread pool or
does it implement its own pool and hands out threads from that one?

I have no idea. If you want to investigate for yourself, here is a link to
the freely-downloadable .Net SDK:

http://www.microsoft.com/downloads/...A6-3647-4070-9F41-A333C6B9181D&displaylang=en

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Kevin Spencer said:
Static objects exist in the heap, which means that they live for the
lifetime of the web application.

But then this means that an asp.net application does have a state, right?
That is good news BTW.
How many ContentTypes do you think one Response can have? (Answer: one)

I meant can I call Response.ContentType = "..." as many times as I want? Are
no headers sent or should I call Response.Clear first?
??? I don't understand what you're trying to get at here. There is only one
Request Queue, and it is managed by IIS. It is used to queue HTTP requests
that arrive while there are no avialable threads to process them.

Well, you did answer my question :)
 
Back
Top