How to get ASP.Net to work at x10Hosting

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=&quot]
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=&quot]In a Microsoft Windows Operating System[/FONT]
  • [FONT=&quot] Using Microsoft Visual Web Developer Express (or Microsoft Visual Studio)[/FONT]
  • [FONT=&quot]Utilising/Targeting Microsoft .Net Framework technologies[/FONT]
  • [FONT=&quot] Testing project on Microsoft ISS server (or Microsoft VS deployment server)[/FONT]
[FONT=&quot] So, not to hard to spot; Microsoft all the way so far. Now, let’s look at the deployment:
[/FONT]
  • [FONT=&quot] Upload project to an Apache server[/FONT]
  • [FONT=&quot] In a Linux Operating System[/FONT]
  • [FONT=&quot] Utilising the Mono Project[/FONT]
[FONT=&quot] See anything missing? x10Hosting (like the majority of web Hosts) do not install Microsoft technologies. As there is competitive open-source (free) software on the market, there really is little need to pay Micro$oft (especially if you’re giving away some of your services for free, as our Host does…).

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" %>
[FONT=&quot]
Or
[/FONT]
HTML:
<!-- this line is for VB.Net projects -->
 <%@ Page Language="VB" AutoEventWireup="false" CodeFile="HelloWorld.aspx.vb" Inherits="HelloWorld" %>
[FONT=&quot]
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>
[FONT=&quot]
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.";
       }
 }
[FONT=&quot]Or
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=&quot]VB.Net users; you may have noticed that I am not attaching an Event Handler as we usually would, like this:
[/FONT]
Code:
'incorrect code
    Protected Sub Button1_Click(ByVal sender As Object, _
                 ByVal e As EventArgs)[B] Handles Button1.Click[/B]

    End Sub
[FONT=&quot]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]
HTML:
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
[FONT=&quot]
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=&quot]Do not upload the web.config file[/FONT]
  • [FONT=&quot] If you have a previous web.config file in your webspace; remove it (or them), as this may break the application [/FONT]
  • [FONT=&quot] Remove any ASP.Net pages from your site that may be broken [/FONT]
  • [FONT=&quot]Open your .htaccess file; if you have any reference to ASP.Net files in there, remove it[/FONT]
  • [FONT=&quot] Now, you may upload the two HelloWorld files you’ve just created to the root of your webspace (/public_html).[/FONT]
[FONT=&quot] If you have performed the above steps correctly, when you navigate to your web domain /HelloWorld.aspx, you will see your page in all its glory – go on, press the Button; you know you want too…

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>
[FONT=&quot]
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:

spangeman

New Member
Messages
6
Reaction score
2
Points
0
How to get ASP.Net to work with MySql at x10Hosting

Pre-reqs
First read this post to get ASP.Net to work at x10Hosting
How to get ASP.Net to work at x10Hosting

Use your C Panel to create a database (MySQL Databases) and create tables and data (phpMyAdmin)

Steps
1. Create a bin folder in the root of your public_html directory

2. Get the two MySql dot net connector dlls and place them in the bin folder
http://dev.mysql.com/downloads/connector/net/6.2.html
MySql.Data.dll
MySql.Web.dll

You may already have these on your PC if you have been developing against a MySql database.

Remember you are running ASP.Net on a Linux Mono box so it is cAsE SenSiTive, please ensure the dll names remain the same as they were when you downloaded them.

3. There are a variety of ways to write the asp.net page but the key point is the connection string must use mysql-chopin.x10hosting.com for the server and not localhost which will work in php and drove me nuts for a couple of days.

4. Example 1
This is how I have set mine up and it is working, you will need to edit the connection string to your own database, username and password. Also the SQL statements table name will need changing to your own tablename.
The asp code came from this tutorial - http://townx.org/blog/elliot/using-m...der-mono-linux


web.config
Code:
     <?xml version="1.0" ?>
    <configuration>
         <appSettings />
         <connectionStrings />
         <system.web>
              <customErrors mode="Off" />
    <compilation>
      <assemblies>
      <add assembly="MySql"/>
        <add assembly="MySql.Data"/>
      </assemblies>
    </compilation>
  </system.web>
</configuration>


aspx Page

Code:
     <%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="MySql.Data.MySqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <title>CD cat</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <script runat="server">
    private void Page_Load(Object sender, EventArgs e)
    {
        string connectionString = "server=localhost;Database=MyDatabase;userid=MyUserId;password=MyPassword;Pooling= false;";
       MySqlConnection dbcon = new MySqlConnection(connectionString);
       dbcon.Open();

       MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT * FROM CDs", dbcon);
       DataSet ds = new DataSet();
       adapter.Fill(ds, "result");

       dbcon.Close();
       dbcon = null;

       ArtistsControl.DataSource = ds.Tables["result"];
       ArtistsControl.DataBind();
    }
    </script>

  </head>

  <body>
    <h1>Artists</h1>
    <asp:DataGrid runat="server" id="ArtistsControl" />
  </body>

</html>


5. Example 2

thegriff has replied to my queries about this with another example, he has placed the connection string in his web.config file and not bothered with any references.
asp.net and mysql
 
Last edited by a moderator:

breakl

New Member
Messages
1
Reaction score
0
Points
0
So if i already have a large, working asp.net site then i am going to have to go through all of it and change the syntax? Is there no automated way to do this? I dont really want to be learning a new language I would rather stick to microsofts asp.net. :(
 

spangeman

New Member
Messages
6
Reaction score
2
Points
0
Not sure what you mean by "change the syntax" breakl. It is only the web.config file which needs to be amended. x10 uses mono asp.net but that doesn't mean you will need to change your syntax it means there may be certain objects and libraries you are using which are not supported under mono, and you will have to use other supported ones instead. There is of course also a good chance that everything you want to use will be supported.
 

untit1ed

New Member
Messages
13
Reaction score
0
Points
0
I still see runtime error on my asp.net page.
and
Code:
<!-- Web.Config Configuration File -->

<configuration>
    <system.web>

        <customErrors mode="Off"/>
    </system.web>
</configuration>
However my web.config has exactly the same configuration (same error with no web.config file).

And there is an error in the tutorial:
Code:
public partial class _Default

and

Partial Class _Default
should be changed to
Code:
public partial class [COLOR=#000080][COLOR=#0000ff]HelloWorld

and

[/COLOR][/COLOR]Partial Class [COLOR=#000080][COLOR=#0000ff]HelloWorld[/COLOR][/COLOR]
 

Hue Kares

New Member
Messages
38
Reaction score
6
Points
0
Hi Untit1ed; thanks for pointing out my typo's, well spotted; it hasn't confused anyone so far, but I'll fix it immediately - cheers.

This tutorial is very basic, and has been tried and tested quite a few times now. Here is a live version so you can confirm it works. I've have looked at some other more complex asp.net pages and they work, so there is currently no issue with our servers (on stoli anyway).

I still see runtime error on my asp.net page.

So erm, did you follow the tutorial, or are we talking about your own custom page? Also, can you please provide some information about the Exception you are getting as your description currently gives us nothing to work with. I'll happily assist you further when you do...

You have omitted the xml declaration from the web.config you posted; please ensure the copy in your webspace contains it.


edit: I can't actually edit the original tutorial, as the Edit button is missing for me for that post; so I'll have to leave it with the errors for now...
 
Last edited:

untit1ed

New Member
Messages
13
Reaction score
0
Points
0
I tried both Default.aspx page generated by VS and your example. I tried it with your web.config and with no web.config file at all. I can't print the detailed error because that's the only output I receive:

Runtime Error.

To see the error modify your web.config as shown below
<!-- Web.Config Configuration File -->

<configuration>
<system.web>

<customErrors mode="Off"/>
</system.web>
</configuration>
It is really weird because the error is still there even when I modify my web.config as the message suggests.
 

Hue Kares

New Member
Messages
38
Reaction score
6
Points
0
Hey there Untit1ed; sorry about these issues you're getting - I'm sure we'll have you up and running soon.

The 'Runtime Error' page you are getting is an error page generated by ASP.Net, which means it's working. ASP.Net is reporting that you have an error on one of your asp.net pages, and you must include a line in your web.config file to see further information on the error (or you could have wrapped your code in a Try/Catch block, and then output the exception details).

I understand you say you've done all this, and you're still getting the same result, which is a little bemusing to me at the moment. However, we will arrive at the answer if we take it step by step, so, for now we must go back to the beginning and start again.

Follow these instructions:

  • Remove all the test pages you've done so far from your webspace - all the asp.Net pages and any web.configs you've uploaded. You should now have no reference to ASP.Net in your entire Webspace.
  • Clear your browser cache
  • Upload the following page to your /public_html directory: ver.aspx
HTML:
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            Response.Write("Your ASP.NET version is: " & System.Environment.Version.ToString())
        Catch ex As Exception
            Response.Write(ex.ToString())
        End Try
    End Sub
   </script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>ASP.Net Test</title>
</head>
<body>
    <form id="form1" runat="server">
    </form>
</body>
</html>
So, when you navigate to your new page, what results do you get? Hopefully, the same as me. However, if it contains errors, no sweat, we'll deal with them, but please post the url to your page, rather than describing it... Also, tell me what server you are on (I assumed it wouldn't make a difference, but perhaps it does :dunno:). Good luck man.


I've only received positive feedback from this tutorial (which I thank everyone for), so I naturally believed that ASP.Net was all fine and working for everyone now - I would like to hear from anyone else who has failed to run a test asp.net page.
 

untit1ed

New Member
Messages
13
Reaction score
0
Points
0
That exapmle works fine:
Your ASP.NET version is: 2.0.50727.1433
I am on lotus server.

UPD: Actually never mind, I just tried to re-upload my old project and it seems to work fine. Sorry for bothering you. Thanks.
 

Hue Kares

New Member
Messages
38
Reaction score
6
Points
0
Thanks for your response Untit1ed; you're most definitely not bothering me man, I give my time freely when I can, in return for all the help I receive from others.

Anyway, I'm glad things are working for you now; cool. I'm gonna go back to assuming the setup is the same on all x10Hostings servers...

Good Luck.

Thanks ranjinap for your kind words.
 

boone1

New Member
Messages
7
Reaction score
0
Points
0
Hi guys,
I have a working webpage in Visual Studio 2005, but when I upload it x10hosting, I get the following error:

"Server Error in '/' Application

Operation aborted due to an exception (see Trace for details).

Description: HTTP 500. Error processing request.

Stack Trace:

System.Configuration.Provider.ProviderException: Operation aborted due to an exception (see Trace for details).
at System.Web.Security.SqliteRoleProvider.RoleExists (System.String roleName) [0x00000]
at System.Web.Security.Roles.RoleExists (System.String rolename) [0x00000]
at ASP.global_asax.Application_Start (System.Object sender, System.EventArgs e) [0x00000]
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000]
"

Any ideas? I have the same web.config file that is on first post, but I added <roleManager enabled="true"/>.

Thanks.
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
To make sure your asp.net code compiles well under mono, use MoMA. MoMA is an utility that will check the code you submit to it and see if it's supported by Mono. http://www.mono-project.com/MoMA
 

espfutbol98

New Member
Messages
200
Reaction score
2
Points
0
I moved my app in C# from Visual Studio 2010 Ultimate to my x10 site and on any page besides the default.aspx page I get the error:
Code:
Server Error in '/' Application
gdiplus.dll

Description: HTTP 500. Error processing request.

Stack Trace:

System.DllNotFoundException: gdiplus.dll
  at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
  at System.Drawing.GDIPlus..cctor () [0x00000] 

Version information: Mono Version: 2.0.50727.1433; ASP.NET Version: 2.0.50727.1433
I got this script right from the asp.net site and I'm not sure exactly what this means as I am new to ASP.Net. Any suggestions?
 

thearchedone

New Member
Messages
18
Reaction score
0
Points
0
Hi,

I've been having problems with my aspx pages... they were working fine, but stopped working one day without me making any changes. Someone pointed me to your post so I decided to copy your example. I deleted all my existing files and followed your instructions but the HelloWorld page does not work either. Here's my code...

Hello world .aspx
<!-- this line is for C# projects -->
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HelloWorld.aspx.cs" Inherits="HelloWorld" %>

<!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 id="Head1" 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>
HelloWorld.aspx.cs:

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class HelloWorld : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Asp.Net post test worked.";
}
}

Web.config:
<?xml version="1.0" ?>
<configuration>
<appSettings />

<connectionStrings />

<system.web>
<customErrors mode="Off" />
</system.web>
</configuration>

All files are located in '/public_html'

The page is hosted here: http://mttracker.x10hosting.com/HelloWorld.aspx

As you can see, it just gives me a blank page... this is exactly what happened with all my other pages.

Please can you help me out... this is driving me mad!!!

Thanks in advance

TAO
 

vishal

-::-X10 Guru-::-
Community Support
Messages
5,255
Reaction score
192
Points
63
Good post ,i thought ASP.net is not supported by x10
 
Top