Library tutorials & articles
Web Enable your C# Program
- Introduction
- The Example
The Example
Now come to business. Let us try out a C# code snippet such that when the user
clicks on the search button, a C# program loads and executes......
Make a file new.cs and write the following lines into it:class test
{
public static void Main()
{
System.Console.WriteLine("hi
<b>it's me");
}
}
Save this file. Using csc.exe compile it, turn it into an .exe, and put it in
proper
apache's cgi-bin subdirectory or allow execute permissions if using IIS
Now, for this we need to modify a few things to our new.html, as follows :
<html>
<form action="http://127.0.0.1/cgi-bin/new.exe">
<input type=submit value=search>
</form>
</html>
We open up the browser type in the url http://127.0.0.1/new.html,
we see what? not "hi it's me " but an "Internal Server Error" ! Panic not !,
we have the exact solution to this. Our new.cs code needs slight modification
to! See the new code below :
class test
{
public static void Main()
{
System.Console.WriteLine("Content-Type:text/html\n");
System.Console.WriteLine("hi<b>it's
me");
}
}
Now if we execute it the same way into the browser, we see no errors! Yes! you
have successfully without spending even a quarter of an hour, made first web-enabled
program in c# ....
Well, last but not the least, here is something for better understanding. Note
the code we used above. In the Content-type , instead of html, I changed it to
plain, well what does output to the monitor ? Don't amaze, it won't flash an
error, rather forthcoming lines containing html tags won't take effect, and behave
as simple text ! Hope you didn't find the reading time hard on you!
Happy coding.
Related articles
Related discussion
-
String was not recognized as a valid DateTime.
by royal ludhiana (19 replies)
-
save .csv with newline character
by James Crowley (1 replies)
-
Loop help needed
by mandy130 (3 replies)
-
ASP.NET Patterns every developer should know
by AndyGrant2005 (2 replies)
-
Create PDF Files on fly in C#
by Geeths (1 replies)
Related podcasts
-
Looking into the C# Crystal Ball with Charlie Calvert and Bill Wagner
One of the most exciting announcements from PDC was the news about C# 4.0 and Visual Studio 2010. With all the excitement and discussion throughout the event about these new developer tools, we reached out to two experts in the fields. Charlie Calvert and Bill Wagner sat down with Keith and Woody...
Events coming up
-
Dec
6
Developing AJAX Web Applications with Castle Monorail
London, United Kingdom
Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!
How do I use data from my form with method post and get?
This thread is for discussions of Web Enable your C# Program.