Best Practices for System.Net Classes what?

J

Janus Knudsen

Hello...

Need a little explanation!

Snippet from MSDN:
"The following recommendations will help you use the classes contained in
System.Net to their best advantage:

Use WebRequest and WebResponse whenever possible instead of type casting to
descendant classes. Applications that use WebRequest and WebResponse can
take advantage of new Internet protocols without needing extensive code
changes. "

Well, it's recommended that you dont type cast to descendant classes - but
what does that mean?

And what classes it referring to?

Regards
Janus
 
D

DalePres

The most common derived classes are HttpWebResponse and HttpWebRequest
classes that are the base for the Page.Request and Page.Response objects
that you no doubt use regularly in ASP.Net.

Dale
 
J

Joerg Jooss

DalePres said:
The most common derived classes are HttpWebResponse and HttpWebRequest
classes that are the base for the Page.Request and Page.Response
objects that you no doubt use regularly in ASP.Net.

No, they're not. These classes are used on the client-side. Page.Request and
Page.Response are instances of System.Web.HttpRequest and
System.Web.HttpResponse respectively.

Cheers,
 
J

Joerg Jooss

Janus said:
Hello...

Need a little explanation!

Snippet from MSDN:
"The following recommendations will help you use the classes
contained in System.Net to their best advantage:

Use WebRequest and WebResponse whenever possible instead of type
casting to descendant classes. Applications that use WebRequest and
WebResponse can take advantage of new Internet protocols without
needing extensive code changes. "

Well, it's recommended that you dont type cast to descendant classes
- but what does that mean?

It means that doing

HttpWebRequest request
= (HttpWebRequest) WebRequest.Create(http://localhost/page.aspx);

is bad... which of course is utter rubbish when you really need to use
low-level technical properties that are only exposed by HttpWebRequest.

Cheers,
 
D

DalePres

Whoops... My mistake. Thanks

Joerg Jooss said:
No, they're not. These classes are used on the client-side. Page.Request and
Page.Response are instances of System.Web.HttpRequest and
System.Web.HttpResponse respectively.

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top