Installing the .NET Framework SDK
Click on setup.exe and after confirming that you do want to install the NET Framework SDK package, and after an interval of a few minutes, you are propelled into the setup wizard:
Click on Next and accept the License agreement to continue. The next dialog after the license agreement will ask you which different pieces of the SDK you need to install. You should check all of them, although if you're short of hard drive space, you could choose to omit the SDK_Samples or documentation. The Software Development Kit is essential:
After clicking on Next you get to a dialog that specifies the destination folder for the different .NET Framework SDK samples and bits and pieces. You can choose to install these wherever you want. More importantly there is a checkbox at the foot of the dialog, which asks you to register environment variables. This checkbox should be checked, as we will use the environment variables in later chapters:
Click on Next and the .NET Framework SDK will install without further ado. It shouldn't require a reboot.
Troubleshooting Hints and Tips
The installation process is very straightforward, and will work on the majority of machines. However, sometimes the particular configuration of your machine will prevent it from installing. Unfortunately we can't cover all of the possible eventualities, but if it doesn't work on yours, you should check that you have enough hard disk space, as this is the most common cause of problems. Also try to ensure that the installation process isn't curtailed half way, as no installer is completely foolproof at removing all the different bits and pieces of the aborted install and it can cause problems when you try to reinstall, and leave you needing to reformat your hard drive to get it to work correctly. Other than that, check the list of newsgroups and resources later in this chapter.
ASP.NET Test Example
Ok, we've now reached the crux of the chapter, checking to see if everything is working correctly. Do you remember the punctual web server code that we talked about earlier in the chapter in which we wanted to write a web page that displays the current time? We'll return to that example now. As you'll see it's quite a simple bit of code, but it should be more than enough to check that ASP.NET is working Okay.
|
Try It Out Your first ASP.NET web page
|
Open up a text editor and type in the following code:
<script language="vb" runat="server">
Sub Page_Load()
time.text=Hour(Now) & ":" & Minute(Now) & ":" & Second(Now)
End Sub
</script>
<html>
<head><title>The Punctual Web Server</title></head>
<body>
<h1>Welcome</h1>
In WebServerLand the time is currently:
<asp:label id="time" runat="server" />
</body>
</html>
|
We strongly suggest (and will assume throughout) that you use Notepad to code all the examples in this book, since it will always do precisely what you ask it to and no more. It's therefore a lot easier to track down any problems you're having, and is a great deal easier than troubleshooting problems caused by FrontPage or similar web page editors.
Save this page as punctual.aspx. Make sure that you save it in the physical folder you created earlier C:\BegASPNET\Ch01\.
When you save the file, you should double-check that your new file has the correct suffix. It should be .aspx, since this is how you tell the web server that the page contains ASP.NET code. Be aware that Notepad (and many other text editors) consider .txt to be the default. So in the Save or Save As dialog, make sure that you change the Save As type to read All Files, or All Files(*.*),or enclose the path and filename in quotes.
Now start up your browser and type in the following: http://localhost/5040/punctual.aspx
Now click on the refresh button of the browser and the displayed time will change. In effect the browser is showing a new and different instance of the same page.
Now on your browser select View Source or similar, (depending on which browser you're using) from the browser menu to see the HTML source that was sent from the web server to the browser. The result is shown below. You can see that there is no ASP.NET code to be seen, and nothing before the first <html> tag the ASP.NET code has been processed by the web server and used to generate pure HTML, which is hard-coded into the HTML source that's sent to the browser:
Here, you can see the HTML that was sent to the browser when I Refreshed the page at 15.39:15.
As we mentioned before, you can expect this to work in any browser because the ASP.NET is processed on the web server. If you have another browser available, try it out.
How It Works
Easy wasn't it? (If you didn't get it to work first time, then don't rush off to email technical support just yet have a little look at the next section, ASP.NET Troubleshooting, first.) Now let's take a look at the ASP.NET code that makes this application tick.
Of course, there is only one block of ASP.NET code (ignoring the server control) in the whole program. It's enclosed by the <script> and </script> tags:
<script language="vb" runat="server">
Sub Page_Load()
time.text=Hour(Now) & ":" & Minute(Now) & ":" & Second(Now)
End Sub
</script>
|
The script delimiters specify which code needs ASP.NET to run, and we'll look at them in detail in the next chapter. If we ignore the <script> tags for the time being, and just think of them as ASP.NET code delimiters, then we're left with just three lines. If we further ignore the Sub Page_Load and End Sub lines, which are standard to many ASP.NET programs, and which we'll be discussing in Chapter 3, we're left with one line. This line:
|
time.text=Hour(Now) & ":" & Minute(Now) & ":" & Second(Now)
|
tells the web server to go off and run the VB.NET Now() function on the web server. The VB.NET Now() function returns the current time at the web server. It returns the values of the Now() function divided up into hour, minute, and second values. The result of this function is returned as part of the <ASP: label> control, further down the page. We'll be looking at this control in Chapter 3.
If the web server and browser are on different machines, then the time returned by the web server might not be the same as the time kept by the machine you're using to browse. For example, if this page is hosted on a machine in Los Angeles, then you can expect the page to show the local time in Los Angeles even if you're browsing to the page from a machine in Cairo.
This example isn't wildly interactive or dynamic, but it illustrates that we can ask the web server to go off and do something for us, and return the answer within the context of an HTML page. Of course, by using this technique with things like HTML forms and other tools, we'll be able to build a more informative, interactive, interface with the user.
|