I have written my first "Hello World" program in ASP. I thought I would post here how it is done and ask if anyone can suggest how to incorporate C#.

The first step was to download the free "Microsoft Visual Web Developer 2005 Express Edition" from microsoft.com

The next step was to install and run this program. Then create a new web page by clicking on File -> New Web Page. This will bring up this windowL

[IMG]http://i67.photobucket.com/albums/h292/Athono/aspnet05.png[/IMG]

From this window, pick "ASP.Net Web Site" and click the OK button.

Then I edited the Default.aspx file so it reads like this:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%
    HelloWorldLabel.Text = "Hello, world!"
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Label runat="server" id="HelloWorldLabel"></asp:Label>

    </div>
    </form>
</body>
</html>

And this works.

So the next step is to incorporate C# into this "Hello World" program. Can anyone make a suggestion?

Recommended Answers

All 6 Replies

You developed this web-based application using VB.NET, when you create an web-based application you'll find language option listed in ComboBox select C# and to write C# code open [YouPageName].aspx.cs like Default.aspx.cs

Well, your file is currently set up to use a VB.NET code file (see the Language="VB" in the Page declaration?) and it looks for that code in Default.aspx.vb. If you add a new page to your website, and select C# as the code-behind language, you'll be ready.

I've attached a screenshot from Visual Studio 2008 (I don't have 2005 handy, but they're similar at this point). The red arrow shows where the language is. The checkbox by the green arrow selects if you want your code at the top of the page (like you did - this is ASP style), or in a separate file dedicated to code (this would be YourPage.aspx.cs, which is ASP.NET style).

As an aside, I recommend you try out Visual Web Developer 2008. There's a lot of new features that have been added in the new version. :)

OK, I fixed everything so that it will work -- or so I thought.

I decided to install some ASP.NET sample code. The installation gave me an error saying that I needed to install the latest version of IIS.

So went into the control panel to add IIS like this:

[img]http://i67.photobucket.com/albums/h292/Athono/IIS.png[/img]

But now, something strange is happening. It is almost as if I have taken one step forward and two steps backwards. Even the most simple ASP.NET program (one I generate without modifying any code at all) produces this in the browser window when I build it and run it:

[img]http://i67.photobucket.com/albums/h292/Athono/simple.png[/img]

Is there some sort of special routine I need to do for IIS?

Taking a wild guess at this (since I'm not very familiar with IIS), I'd first assume that for some reason it's not set to process .aspx files through the ASP engine. My assumption is largely based on the fact that the ASP markup should never reach the client. Unfortunately, I don't know how to reconfigure that properly.

One potential workaround is to create your projects as File System websites. This will cause them to be processed by Cassini, which is a mini-IIS packaged with VWD, instead of using your computer's IIS. Note that this will cause complications if you try to deploy your websites to a server, as the server will use IIS. But if you're just playing around with ASP.NET, file system webs should get you going for now.

IIS was installed and started after the .NET framework.
This was the cause of some problems.
But I fixed it.

On the command line, I went to

C:\WINDOWS\Microsoft.NET\Framework\

and went to the directory of the latest version:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

and I typed

aspnet_regiis -i

the computer responded that it was installing ASP.NET

and now, my programs work.


aspnet_regiis -i

So many times have I redone my dev machine and couldn't figure out why IIS wasn't working right. Then I forgot this little step and I feel 1 inch tall.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.