..
The best way to start using ASP.NET is to create a simple application. First we create a directory to put the files of our application (in my case C: \ esempioaspnet). Then we create a virtual directory in IIS, right click on Default Web Site -> New -> Virtual Directory

This opens the following window where we enter a name for our application / website (in my case SitoTest)

continuing on, you must set the physical path of the folder you created earlier (esempioaspnet)

Finally we set the access permissions to the directory

In practice SitoTest the alias will be the name by which the application will be known by the outside world.
At this point we have to create our first HTML page. We can safely use an editor like Notepad, or use Visual Studio. Since it is just a very simple example Notepad, then open a new document and write the following code:
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> SitoTest Page </ title> </ head> <body> <h1> Hello World </ h1> Hello this is a test </ Body> </ Html>
save the file with the extension htm (hello.htm) and put this in your C: \ esempioaspnet. At this point, launching a browser and typing the address http://localhost/SitoTest/hello.htm the result is as follows.

In practice, the browser sends an HTTP request to the server for the file hello.htm and IIS returns the contents of the file to the browser. Because the text contains HTML tags will include the browser and displays the content properly what we expect. Until now, however we are not faced with a ASP.NET page, but a simple HTML page.
To make the conversion from HTML to ASP.NET requires two steps: add hello.htm top of the file one line of code (the Page directive) and rename the file itself to be hello.htm hello.aspx. In this way we will have a version of our program that operates using the ASP.NET framework
<% @ Page Language = "C #"%> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> SitoTest Page </ title> </ head> <body> <h1> Hello World </ h1> Hello this is a test </ Body> </ Html>The result is visually unchanged, but the Page directive is used by the runtime in ASP.NET compilation of the file and compile this code suggests interpreting any instructions placed inside the form of C # code.
And 'possible to insert executable code in our pages simply as follows:
<body> <h1> Hello World </ h1> <% ....... this.Metodo1 (); this.Metodo2 (); ....... %> </ Body>
It 'can also insert blocks of code to be executed on the server. To do this you use the runat:
<% @ Page Language = "C #" Debug = "true"%>
<script runat="server">
MetodoTest void () {
/ / Method that does something
}
</ Script>
<html>
<body>
<h1> Hello World </ h1>
<%
MetodoTest ();
%>
</ Body>
</ Html>
| |
ASP (Advanced)
Full course for creating dynamic Web sites. From 39 €. |
| |
ASP.NET (Course)
Full course for building Web applications from 49 €. |
| |
SQL and Database (Course)
Create and manage relational databases. From 39 €. |