Problem Set 10
Up Problem Set 0 Problem Set 1 Problem Set 2 Problem Set 3 Problem Set 4 Problem Set 5 Problem Set 6 Problem Set 7 Problem Set 8 Problem Set 9 Problem Set 10

 

ASP.NET
Programming Web Services

Due 11:59pm on Friday, December 8

This assignment will focus on building a simple web application.  When a user connects to the webpage that you design, he or she will be able to choose a favorite movie (or music group, or pizza topping, or sport, or whatever -- you decide) from a fixed list of choices, and then see the result of the overall vote, i.e. the result of all users who have submitted a vote so far.  Once a user has submitted a vote, he or she is not allowed to do so again (at least not during the same session).  The computer that holds your CS112 files (namely "m:" on the CS-112 servers) is also a web server, so you will be able to run your program from any computer having Internet access -- that's the point of web services.

There is one caveat in this assignment:  VS.NET will not work in developing your program!  There are a couple of technical reasons for this, but the bottom line is that you will have to rely on the error messages generated by the web browser when running your program in order to debug it.  I suggest using WordPad to actually create and edit your files.

Note:  In order for error messages to appear in your browser, you must tell the web server to allow them to be displayed.  To do that, create a file called "web.config" in the same directory that you are creating your solution (see below).  This file should contain the following code:

    <configuration>
        <system.web>
            <customErrors mode="Off"/>
        </system.web>
    </configuration>

In terms discussed in the textbook, your program will utilize "code behind", will communicate to the server via "post data", and will implement "session tracking".  It will not implement a "three-tier architecture", however, because we have not learned about databases.  Instead, it will simply write to a file.  Although your program will be very simple, it should nevertheless give you a good feel for how these things work in the real world.

More specifically, your webpage should have the following components:

bullet

Some kind of "welcome" message at the top.

bullet

A list of movies (or music groups, or sports, etc) displayed using radio buttons.

bullet

A "Submit" button that will submit the user's choice.  When it is pressed the first time,
a message should appear thanking the user for his or her vote.  When it is pressed subsequently,
a message should appear informing the user that he or she can only vote once.

bullet

A "Results" button that will display the current vote tally for each choice when pressed.

Note: a key thing to remember is that HTTP sessions are stateless -- everything you need to remember about a session must be explicitly stored somewhere.  In this application, there are two pieces of state that need to be remembered:

  1. Whether or not the Submit button has already been pressed or not.  The session tracking capability should be used to keep track of this (which it does using a "cookie", a file stored on the user's machine, but that detail is hidden from you).  I suggest following the example in the text in order to do this, using the "Session.Add" capability.  If you have trouble understanding the example, you can read in Chapter 12 about "collections", which is what the Session feature is.
     

  2. The totals of the votes for each choice made by all of the users.  The code behind that's running on the server should write this information to a file (since we don't have a database).  I would recommend simply storing the information as space-delimited data.  For example, the file contents "3 17 4 9" might indicate 3 votes for football, 17 for lacrosse, 4 for basketball, and 9 for bowling (assuming that "Favorite Sports" are being voted on).

    Note:  The file that you write to, let's call it Results.txt, should be referred to as the C# string:
           
    "e:/cs112/<netid>/Results.txt"
    This is because your C# program will run on plucky (the web server), and the above points to where the files really live on plucky.  If you prefer using backslashes, you should write:
           
    "e:\\cs112\\<netid>\\Results.txt"
    The reason we need two backslashes is that the filename is a C# string, but remember that backslash is the "escape" character (for things like "\n"), so "\\" is really just one backslash!

The result of your assignment should be two files:

  1. An ASP file called Vote.aspx containing the HTML code that dictates the visual appearance of your web page.

  2. A C# file called Vote.aspx.cs containing the C# "code behind" that controls the dynamic behavior of your webpage.

You should create these files using WordPad in the top-level of the m:/ directory in your account.  Do not put the files in the Visual Studio Projects folder.  If you do, the web server will not be able to "see" them, and they will not execute properly.  I suggest creating the ASP file first, and get the "look and feel" of the webpage to be correct.  Then you can add the C# file to get the dynamic behavior to work correctly.

In order to run your program, just type the following URL into your favorite browser:

    http://plucky.cs.yale.edu/CS112ASP/netid/Vote.aspx

where "netid" is your netid.   Plucky is the machine that actually holds the "m:" drive on the CS112 servers, and the above URL is how your folder is accessed via the Internet (i.e. via HTTP).  The Firefox browser has now been installed on all of the CS112 servers, so you can use it to test your programs without logging off of the servers.

Final comment:  This is the first time I have given a web-application assignment in this course, so please let me know if you run into any problems, and please stay tuned to this website for updates or hints.