Hue Kares
New Member
- Messages
- 38
- Reaction score
- 6
- Points
- 0
THIS TUTORIAL IS NO LONGER VALID; X10HOSTING'S FREE SERVICES NO LONGER SUPPORT ASP.NET. This tutorial is here for Illuminated and Premium, which do support it.
[FONT="]
OK, so you’ve built a brilliant ASP.Net website, and now you want to show it to the world. You upload the pages to your webspace, only to discover it doesn’t work…
Well, there are very good reasons why, and it’s pretty simple to get it work, once you understand what’s going on. In this tutorial, we are going to understand how ASP.Net works here at x10Hosting, and how to deploy your projects successfully.
Background
How do you write and deploy an ASP.Net page? Well, for most of us, it’s as follows (see if you can spot the theme!):
[/FONT]
[/FONT]
So can you use ASP.Net (a Microsoft technology) here at x10Hosting? The answer is a big fat Yes; absolutely. x10Hosting (unlike the majority of web hosts) have installed the Mono Project on their servers, which allows it to build ASP.Net pages.
In very simple terms, the Mono Project is an open-source copy of the .Net Framework. The Namespaces and Classes are the same in both frameworks, which should mean you do not have to change your code; what works on Windows/.Net, will also largely work on Linux/Mono.
Now, this isn’t always true for a few good reasons. As an open-source project, Mono lags behind in development compared to the might of the Microsoft team building the .Net Framework. VB.Net support is very poor; according to its documentation, only version VB8 (VB2005) is allowed currently. C# users will be happy to know they can utilise most of the latest (C# version 3) language enhancements, including LINQ.
As an ASP.Net developer, it will be important for you to look at the documentation, and familiarise yourself with the key (and subtle) differences between the frameworks. If you really get to know the Mono Project, you will discover it has some real gems of it’s own to offer.
Let’s get Coding…
When creating an ASP.Net page, you will create two files; pageName.aspx containing the xhtml, and pageName.aspx.vb or pageName.aspx.cs containing the code.
An XML document called web.config is also created. This contains configuration and settings for your site or a specific project. For now, we’re going to ignore this file. It is important, so we’ll come back to it later.
I’ll use a version of the world famous and painfully boring “Hello World!” program as an example of how easy it is to deploy an ASP.Net project, using C# or VB.Net. However, we’ll put a Button on ours, to make it exciting!
Using Visual Web Developer 2008 Express, create a new website. Ignore the Default.aspx, and add a new Web Form called HelloWorld.aspx. Now, place a Label and a Button on to the page.
Here’s the xHTML (HelloWorld.aspx):
[/FONT]
[FONT="]
Or
[/FONT]
[FONT="]
And this is the rest of xhtml for both languages:
[/FONT]
[FONT="]
That’s the html sorted. Now on to the code-behind file.
C# HelloWorld.aspx.cs:
[/FONT]
[FONT="]Or
VB.Net HelloWorld.aspx.vb:
[/FONT]
[FONT="]VB.Net users; you may have noticed that I am not attaching an Event Handler as we usually would, like this:
[/FONT]
[FONT="]This will produce an error when you deploy the page, as VB.Net support in Mono is very out of date. To solve this issue, we need to call the Methods by their name instead of attaching a Handles clause. As you can see, the Method is raised directly in the xhtml:
[/FONT]
[FONT="]
Run the project on your computer, to see it should work just fine. OK, now we’re almost ready to upload the files to our server. This is the really important bit – follow these steps:
[/FONT]
Can you believe it was that simple? Me either! It seems that ASP.Net is as easy to utilise on x10Hosting servers as php or Python.
A trouble-free web.config
You will need a web.config file, to store database connection strings or to display specific error pages, for example. So, let’s create a new one. You may ask why create one when our project has created one already? Well, as I've shown, you don’t need all that stuff it creates, and some of it will cause trouble…
Here’s our new global web.config xml file:
[/FONT]
[FONT="]
Now we’re done; Upload the file to the root of your webspace (/public_html).
Currently, our web.config only performs one task - if your ASP.Net pages have any errors on them, the specific error information will now be displayed for you, which will make your debugging so much easier. You can discover what else you can do with your web.config in the Config section of the Mono documentation.
As you placed this web.config in your root directory, it will apply to all ASP.Net pages in your webspace. You may add different web.config files to subdirectories only if you really need to manage specific pages contained in that subdirectory.
--------------------------------
Thank you for reading this tutorial for beginners; if you are an aspiring ASP.Net developer, I hope you will now find the process much easier. If you didn’t bother reading any of this, I basically took over 1,000 words to say “delete web.config”!
[/FONT]
Possible fix:
[FONT="]
OK, so you’ve built a brilliant ASP.Net website, and now you want to show it to the world. You upload the pages to your webspace, only to discover it doesn’t work…
Well, there are very good reasons why, and it’s pretty simple to get it work, once you understand what’s going on. In this tutorial, we are going to understand how ASP.Net works here at x10Hosting, and how to deploy your projects successfully.
Background
How do you write and deploy an ASP.Net page? Well, for most of us, it’s as follows (see if you can spot the theme!):
[/FONT]
- [FONT="]In a Microsoft Windows Operating System[/FONT]
- [FONT="] Using Microsoft Visual Web Developer Express (or Microsoft Visual Studio)[/FONT]
- [FONT="]Utilising/Targeting Microsoft .Net Framework technologies[/FONT]
- [FONT="] Testing project on Microsoft ISS server (or Microsoft VS deployment server)[/FONT]
[/FONT]
- [FONT="] Upload project to an Apache server[/FONT]
- [FONT="] In a Linux Operating System[/FONT]
- [FONT="] Utilising the Mono Project[/FONT]
So can you use ASP.Net (a Microsoft technology) here at x10Hosting? The answer is a big fat Yes; absolutely. x10Hosting (unlike the majority of web hosts) have installed the Mono Project on their servers, which allows it to build ASP.Net pages.
In very simple terms, the Mono Project is an open-source copy of the .Net Framework. The Namespaces and Classes are the same in both frameworks, which should mean you do not have to change your code; what works on Windows/.Net, will also largely work on Linux/Mono.
Now, this isn’t always true for a few good reasons. As an open-source project, Mono lags behind in development compared to the might of the Microsoft team building the .Net Framework. VB.Net support is very poor; according to its documentation, only version VB8 (VB2005) is allowed currently. C# users will be happy to know they can utilise most of the latest (C# version 3) language enhancements, including LINQ.
As an ASP.Net developer, it will be important for you to look at the documentation, and familiarise yourself with the key (and subtle) differences between the frameworks. If you really get to know the Mono Project, you will discover it has some real gems of it’s own to offer.
Let’s get Coding…
When creating an ASP.Net page, you will create two files; pageName.aspx containing the xhtml, and pageName.aspx.vb or pageName.aspx.cs containing the code.
An XML document called web.config is also created. This contains configuration and settings for your site or a specific project. For now, we’re going to ignore this file. It is important, so we’ll come back to it later.
I’ll use a version of the world famous and painfully boring “Hello World!” program as an example of how easy it is to deploy an ASP.Net project, using C# or VB.Net. However, we’ll put a Button on ours, to make it exciting!
Using Visual Web Developer 2008 Express, create a new website. Ignore the Default.aspx, and add a new Web Form called HelloWorld.aspx. Now, place a Label and a Button on to the page.
Here’s the xHTML (HelloWorld.aspx):
[/FONT]
HTML:
<!-- this line is for C# projects -->
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HelloWorld.aspx.cs" Inherits="HelloWorld" %>
Or
[/FONT]
HTML:
<!-- this line is for VB.Net projects -->
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="HelloWorld.aspx.vb" Inherits="HelloWorld" %>
And this is the rest of xhtml for both languages:
[/FONT]
HTML:
<!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>Hello World!</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Erm, Hello World!"></asp:Label>
<br /> <br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Press Me" />
</div>
</form>
</body>
</html>
That’s the html sorted. Now on to the code-behind file.
C# HelloWorld.aspx.cs:
[/FONT]
Code:
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Asp.Net post test worked.";
}
}
VB.Net HelloWorld.aspx.vb:
[/FONT]
Code:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Label1.Text = "ASP.Net post test Worked"
End Sub
End Class
[/FONT]
Code:
'incorrect code
Protected Sub Button1_Click(ByVal sender As Object, _
ByVal e As EventArgs)[B] Handles Button1.Click[/B]
End Sub
[/FONT]
HTML:
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
Run the project on your computer, to see it should work just fine. OK, now we’re almost ready to upload the files to our server. This is the really important bit – follow these steps:
[/FONT]
- [FONT="]Do not upload the web.config file[/FONT]
- [FONT="] If you have a previous web.config file in your webspace; remove it (or them), as this may break the application [/FONT]
- [FONT="] Remove any ASP.Net pages from your site that may be broken [/FONT]
- [FONT="]Open your .htaccess file; if you have any reference to ASP.Net files in there, remove it[/FONT]
- [FONT="] Now, you may upload the two HelloWorld files you’ve just created to the root of your webspace (/public_html).[/FONT]
Can you believe it was that simple? Me either! It seems that ASP.Net is as easy to utilise on x10Hosting servers as php or Python.
A trouble-free web.config
You will need a web.config file, to store database connection strings or to display specific error pages, for example. So, let’s create a new one. You may ask why create one when our project has created one already? Well, as I've shown, you don’t need all that stuff it creates, and some of it will cause trouble…
Here’s our new global web.config xml file:
[/FONT]
Code:
<?xml version="1.0" ?>
<configuration>
<appSettings />
<connectionStrings />
<system.web>
<customErrors mode="Off" />
</system.web>
</configuration>
Now we’re done; Upload the file to the root of your webspace (/public_html).
Currently, our web.config only performs one task - if your ASP.Net pages have any errors on them, the specific error information will now be displayed for you, which will make your debugging so much easier. You can discover what else you can do with your web.config in the Config section of the Mono documentation.
As you placed this web.config in your root directory, it will apply to all ASP.Net pages in your webspace. You may add different web.config files to subdirectories only if you really need to manage specific pages contained in that subdirectory.
--------------------------------
Thank you for reading this tutorial for beginners; if you are an aspiring ASP.Net developer, I hope you will now find the process much easier. If you didn’t bother reading any of this, I basically took over 1,000 words to say “delete web.config”!
[/FONT]
Possible fix:
This contains a couple issues.
the Class in the .cs(or vb) file doesn't match the class specified in the aspx file:
Code:AutoEventWireup="true" CodeFile="HelloWorld.aspx.cs" Inherits="HelloWorld" %>
public partial class _Default needs to be public partial class HelloWorld or Inherits="HelloWorld" needs to be Inherits="_Default "
Last edited by a moderator: