System.Web and web related questions 
Author Message
 System.Web and web related questions

Hi all.

I did the actual work in J#, but I think the same classes and method names
also applies to C#. I would like to post it to the J# group but don't have
access. Sorry for anything off topic.

1) Is System.Web.HttpApplicationState the equivalent of
javax.servlet.ServletContext? ServletContext can store information through
get and set methods that can be shared with all users of a web application.

2) In Java, I got the session object by calling the method getSession() of
the javax.servlet.http.HttpServletRequest object. In C# (J#), I don't see an
equivalent method in System.Web.HttpRequest. Can I get it from a class, or
must I directly pass the "Session" (?) object from the aspx page into my
class?

3) In Java, there is a method called encodeURL( String link ) in class
HttpServletResponse. This method would encode the "session id" into the link
if the browser did not support cookies. How do you deal with this in C#
(J#)? If a user does not have cookies turned on, does the webserver
automatically encode the URL? Or is there a method I like encodeURL()?

4) In Java, I got the parameter values of a form or information from a link
with the method getParameter( String name ) from the HttpServletRequest
object. For example, if the html form had a text field named, "firstName", I
could use getParameter( "firstName" ) to get the value of that field. I see
there is a method called get_Item( String name ) in System.Web.HttpRequest.
Is this the same thing? Will it also work if I want to get first name value
from a link like: http://www.*-*-*.com/

5) What are the default objects in the aspx code?

Is there an object that represents:

HttpApplicationState (I assume this is the equivalent to ServletContext)?
HttpSessionState (Session?)
HttpRequest
HttpResponse

6) How do you handle this in C# (J#): You have a web form with text fields.
You also have a field and a button. Clicking on the button brings up a
window listing your hd files, you choose a file, and click okay. Then
clicking on the submit button on the web page, you send the info in the
fields, as well as *uploading* the selected file to the server.

What kind of code would I need to write to extract the field values, as well
as the file they uploaded?

7) I looked at the API docs from MS. What is the difference between a
"Property" and a "Member" of a class? They seem like the same thing to me.
To get a property/member, for example : PropertyOne, would I write:

PropertyOneClass poc = SomeClass.PropertyOne;

8) Do the API docs list inherited methods of the superclass? If not, why
not?

Thanks all in advance.



Sun, 30 Jan 2005 09:46:00 GMT  
 System.Web and web related questions
Daniel,

    See inline.


Quote:
> Hi all.

> I did the actual work in J#, but I think the same classes and method names
> also applies to C#. I would like to post it to the J# group but don't have
> access. Sorry for anything off topic.

> 1) Is System.Web.HttpApplicationState the equivalent of
> javax.servlet.ServletContext? ServletContext can store information through
> get and set methods that can be shared with all users of a web

application.

    Looking at the documentation for javax.servlet.ServletContext, it would
seem that you might want to look at the IHttpHandler interface.  This is the
interface used to handle HTTP requests at the most basic level (it is
provided to you through the context, which is passed in the call to
ProcessRequest).

Quote:

> 2) In Java, I got the session object by calling the method getSession() of
> the javax.servlet.http.HttpServletRequest object. In C# (J#), I don't see
an
> equivalent method in System.Web.HttpRequest. Can I get it from a class, or
> must I directly pass the "Session" (?) object from the aspx page into my
> class?

    You can get it from the static Current property on the HttpContext
class.  This will give you the current HttpContext, from which you can get
the HttpSession by looking at the Session property.

Quote:

> 3) In Java, there is a method called encodeURL( String link ) in class
> HttpServletResponse. This method would encode the "session id" into the
link
> if the browser did not support cookies. How do you deal with this in C#
> (J#)? If a user does not have cookies turned on, does the webserver
> automatically encode the URL? Or is there a method I like encodeURL()?

    You have to modify the web.config file to do this.  In the sessionState
element, you can set the cookieless property to true, and it will adjust the
urls for you (all of your urls in your pages should be relative to take
advantage of this).

Quote:

> 4) In Java, I got the parameter values of a form or information from a
link
> with the method getParameter( String name ) from the HttpServletRequest
> object. For example, if the html form had a text field named, "firstName",
I
> could use getParameter( "firstName" ) to get the value of that field. I
see
> there is a method called get_Item( String name ) in

System.Web.HttpRequest.

Quote:
> Is this the same thing? Will it also work if I want to get first name
value
> from a link like: http://www.web.com/firstName=FooBar?

    If you want to get the values from the URL string, then you use the
QueryString property exposed by the Request property, like this:

// Get the firstname property:
string pobjFirstName = HttpContext.Current.Request.QueryString["firstName"];

    To get from a form field, use the items property like you noticed
before, but in C#, the shorthand is this:

// Get the firstName field on the form.
string pobjFirstName = HttpContext.Current.Request["firstName"];

Quote:

> 5) What are the default objects in the aspx code?

> Is there an object that represents:

> HttpApplicationState (I assume this is the equivalent to ServletContext)?
> HttpSessionState (Session?)
> HttpRequest
> HttpResponse

    All of these are exposed on the Page object which your object derives
from.  The properties you mentioned are exposed by the following properties:

Application
Session
Request
Response

Quote:

> 6) How do you handle this in C# (J#): You have a web form with text
fields.
> You also have a field and a button. Clicking on the button brings up a
> window listing your hd files, you choose a file, and click okay. Then
> clicking on the submit button on the web page, you send the info in the
> fields, as well as *uploading* the selected file to the server.

> What kind of code would I need to write to extract the field values, as
well
> as the file they uploaded?

    You have to use an <input type="file"> tag in the HTML, as well as
change the form encoding type.  The files are exposed on the Request through
the Files property.

Quote:

> 7) I looked at the API docs from MS. What is the difference between a
> "Property" and a "Member" of a class? They seem like the same thing to me.
> To get a property/member, for example : PropertyOne, would I write:

> PropertyOneClass poc = SomeClass.PropertyOne;

    A property is like a field, except that code can be executed when it is
set/get.  A method is just a method call, like it is in Java.

Quote:

> 8) Do the API docs list inherited methods of the superclass? If not, why
> not?

    Yes, they do, and they also say in the listing "(inherited from xxx)" to
indicate that it is inherited.

Quote:

> Thanks all in advance.

    Hope this helps.

--
               - Nicholas Paldino [.NET/C# MVP]



Sun, 30 Jan 2005 22:16:38 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Adding Web Controls to the System.Web.UI.WebControls namespace

2. Programming related web site

3. Add C# Web User Controls to a VB.Net Web App

4. Visual C++ Web Service & ASP Web Controls

5. Output types for web methods in c# web service

6. Deploying web applications with a web service

7. Namespace Conflict - c# Class Library used by Web Service and ASP.NET Web App

8. Access C/C++ Newsgroups via the web - Free Web based News server

9. ATL Server - Web Application/Web Service

10. Redirect web request to diffrent web site from an ISAPI filter

11. Windows CE Web Server: Using Web Tools to Monitor and Manage Embedded Devices

12. Web Service with existing web server

 

 
Powered by phpBB® Forum Software