views:

83

answers:

5

I have just started learning C#.

Can anyone explain the technical differences between a .Net desktop application and a web application?.

I mean for example, if I have a simple HelloWorld application using a WinForm, what are the steps required to change that into a HelloWorld web application?

+2  A: 

There's no real way to make a "fair comparison" as the two really are like "chalk and cheese". A desktop application has one "entry point", running the executable whereas a web application has many, each .aspx page that you've created.

There's no "easy" way to convert a "Hello World" application as the UI/presentation models are so completley different. A classic console application is entirely written in code using Console.WriteLine, whereas a webforms application that says "Hello World" can be written entirely in asp.net markup.

An asp.net "Hello World" application can be as simple as a file called default.aspx containing:

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

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
Hello, world!
    </form>
</body>
</html>

Whereas the console/desktop application equivalent is:

using System;
namespace ConsoleHelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Hello World");
        }
    }
}
Rob
thanks - I see they are quite different ;)
n00bie_lucy
@n00bie_lucy, welcome to stackoverflow =) If you're happy that my answer answered your question then please mark it as "accepted" by clicking on the tick to the left of my answer. That said, there's a *lot* more that can be said on this subject, so I'd suggest having a play around with asp.net AND windows forms and coming back to this site and asking any new questions that doing so generates =)
Rob
A: 

An ASP.NET webpage (or any active web page: Perl, cgi-bin php etc) is a short program, which runs for a moment, produces a stream of html, and terminates, making a web application much closer to a collection of console applications, than to a interactive WinForm application.

James Curran
A: 

There are quite a few ways to write desktop applications, each of which would require completely different porting to be turned into a web application. I'll give just a couple of examples.

A console application could be invoked via something like a CGI script to display its output over the web without any modification to the console application itself (as long as it was a simple one that didn't require any interactive input).

Silverlight supports a (fairly substantial) subset of WPF applications. It would be fairly trivial to code a hello world kind of thing in the common subset, so the same source code would produce either a desktop application or a Silverlight web application.

Jerry Coffin
A: 

Changing a desktop application to a web application would involve setting up a web server to serve up webpages and converting each dialog from the app to a webpage. The functionality/business logic would go into the "code behind" pages (in WebForms) and in the models/controllers (in MVC). There might be some visual redesign involved as well, but you could always just start with a 1-to-1 conversion and go from there.

Web applications often require slightly different design principles than desktop applications. For example, through a website, you won't have access to the user's harddrive. You would also have to handle multiple concurrent users on your site whereas the same users running the desktop application at the same time would do so in isolation from each other.

Anna Lear
very helpful Anna - thanks. So much to learn!
n00bie_lucy
A: 

It's kind of a large subject to cover in one SO post. Some things I would recommend understanding:

There is a lot more to understand than this, but it's a good place to start...

Abe Miessler