+ Reply to Thread
Page 1 of 3
1 2 3 LastLast
Results 1 to 10 of 26

Thread: How to get ASP.Net to work at x10Hosting

  1. #1
    x10Hosting Member Hue Kares is an unknown quantity at this point Hue Kares's Avatar
    Join Date
    Feb 2009
    Location
    UK
    Posts
    37

    Lightbulb How to get ASP.Net to work at x10Hosting

    ASP.Net for Beginners
    (aka “But it worked on Windows!?!”)

    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!):
    So, not to hard to spot; Microsoft all the way so far. Now, let’s look at the deployment:
    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):
    HTML Code:
    <!-- this line is for C# projects -->
     <%@ Page Language="C#" AutoEventWireup="true" CodeFile="HelloWorld.aspx.cs" Inherits="HelloWorld" %>

    Or
    HTML Code:
    <!-- 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:
    HTML Code:
    <!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:
    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.";
           }
     }
    Or
    VB.Net HelloWorld.aspx.vb:
    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
    VB.Net users; you may have noticed that I am not attaching an Event Handler as we usually would, like this:
    Code:
    'incorrect code
        Protected Sub Button1_Click(ByVal sender As Object, _
                     ByVal e As EventArgs) Handles Button1.Click
    
        End Sub
    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:
    HTML Code:
    <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:
    • Do not upload the web.config file
    • If you have a previous web.config file in your webspace; remove it (or them), as this may break the application
    • Remove any ASP.Net pages from your site that may be broken
    • Open your .htaccess file; if you have any reference to ASP.Net files in there, remove it
    • Now, you may upload the two HelloWorld files you’ve just created to the root of your webspace (/public_html).
    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:
    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”!

    If anyone has any comments, questions or corrections, I would gratefully welcome them.



  2. #2
    x10Hosting Member spangeman is an unknown quantity at this point
    Join Date
    Oct 2009
    Posts
    6

    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" />
             </system.web>
       </configuration>
       <configuration>
      <system.web>
        <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=mysql-chopin.x10hosting.com;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 spangeman; 10-30-2009 at 04:43 AM.

  3. #3
    Administrator Brandon is an unknown quantity at this point Brandon's Avatar
    Join Date
    Jun 2006
    Location
    The ghetto aka Tbury, Massachusetts
    Posts
    8,260

    Re: How to get ASP.Net to work at x10Hosting

    There we go.
    Thanks,
    Brandon, x10Hosting Administrator
    (97 571-9054

  4. #4
    x10Hosting Member breakl is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    1

    Re: How to get ASP.Net to work at x10Hosting

    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.

  5. #5
    x10Hosting Member spangeman is an unknown quantity at this point
    Join Date
    Oct 2009
    Posts
    6

    Re: How to get ASP.Net to work at x10Hosting

    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.

  6. #6
    x10Hosting Member axilomx is an unknown quantity at this point
    Join Date
    Oct 2009
    Posts
    3

    Re: How to get ASP.Net to work at x10Hosting

    This is a very good start... thanks for posting it

  7. #7
    x10Hosting Member untit1ed is an unknown quantity at this point
    Join Date
    Oct 2009
    Posts
    10

    Re: How to get ASP.Net to work at x10Hosting

    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 HelloWorld
    
    and
    
    Partial Class HelloWorld

  8. #8
    x10Hosting Member Hue Kares is an unknown quantity at this point Hue Kares's Avatar
    Join Date
    Feb 2009
    Location
    UK
    Posts
    37

    Re: How to get ASP.Net to work at x10Hosting

    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).

    Quote Originally Posted by untit1ed View Post
    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 by Hue Kares; 11-14-2009 at 09:05 PM. Reason: added note re: editing original post

  9. #9
    x10Hosting Member untit1ed is an unknown quantity at this point
    Join Date
    Oct 2009
    Posts
    10

    Re: How to get ASP.Net to work at x10Hosting

    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.

  10. #10
    x10Hosting Member Hue Kares is an unknown quantity at this point Hue Kares's Avatar
    Join Date
    Feb 2009
    Location
    UK
    Posts
    37

    Re: How to get ASP.Net to work at x10Hosting

    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 Code:
    <%@ 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.

+ Reply to Thread
Page 1 of 3
1 2 3 LastLast

Similar Threads

  1. Replies: 10
    Last Post: 09-19-2009, 01:05 PM
  2. Ok, so I'm trying to decided wether to use asp.net or php
    By mrfish in forum Programming Help
    Replies: 8
    Last Post: 06-16-2009, 05:59 AM
  3. Website not work - goes to x10hosting homepage
    By MIKE-STAMP in forum Scripts & 3rd Party Apps
    Replies: 6
    Last Post: 12-08-2007, 10:15 PM
  4. Replies: 6
    Last Post: 09-28-2006, 03:52 PM
  5. Account Suspended
    By tehpwner in forum Free Hosting
    Replies: 7
    Last Post: 10-17-2005, 07:08 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts