ASP.Net – Simple webpage

ASP.Net is a web framework for building websites. ASP.Net has been designed to be fully integrated with the .Net framework. ASP.Net works with Internet Information Services (IIS) to deliver the content. ASP.Net pages are with .aspx extension.

ASP.Net files can contain server-side controls, client-side controls, and validation controls. Other than these, it supports placing HTML objects along with HTML code, client-side script code, and processing instructions for the server.

One important aspect of ASP.Net is, it can separate code from HTML. So that it will be easy to manage the projects developed using ASP.Net. ASP.Net allows using all .Net classes within its web pages.

Simple ASP.Net web page

Let’s create a simple web page. Save the file as Default.aspx.

<%@ Page Language="C#" %>

<html>
    <head>
        <title>Sample ASP.Net Page</title>
    </head>

    <body>
        <form runat="server">
            <h1>
               <%
                   string s = DateTime.Now.ToString();
                   Response.Write(s);
               %>
            </h1>
        </form>
    </body>
</html>

We have added the @Page directive to instruct the language we are using on our ASP.Net page. If not mentioned language attribute; by default, ASP.Net considers “Visual Basic .Net” language.

We have added the <form> tag to our HTML code, and instruct the code on the server-side by adding runat attribute. This is an important attribute to instruct the code to run at either server-side or client-side.

We used the DateTime class’s member Now to get the current date and time; and return it using Response. Write function.

Once we saved the “Default.aspx” file; configure this into IIS (Internet Information Services) to enable to access the “Default.aspx” file through web-browser.

Look at this article to configure a folder in Internet Information Services. “How to create Virtual Directory in Internet Information Services (IIS)

Now open the web browser and type the following in the address bar: We have created a virtual directory with the name first for our directory where Default.aspx exists.

localhost/first/

It runs our Default.aspx page and displays the current date and time on the page.

..

ASP.Net – Simple webpage

One thought on “ASP.Net – Simple webpage

Leave a Reply

Your email address will not be published.

Scroll to top