Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- install mono:
- sudo apt-get install mono-runtime
- sudo apt-get install mono-gmcs
- Install mod_mono:
- sudo apt-get install libapache2-mod-mono
- sudo apt-get install mono-apache-server2
- Enable mod_mono autoconfig:
- sudo a2enmod mod_mono_auto
- For new installation this is all that's need to enable mod_mono.
- For older installation with existing Apache configuration files, make sure the following directives somewhere in one of Apache configuration files.
- For new installation the following are already included in /etc/mono-server4/mono-server4-hosts.conf, which is included in the main configuration file.
- make sure this is in /etc/mono-server4/mono-server4-hosts.conf:
- MonoAutoApplication enabled
- MonoServerPath default /usr/bin/mod-mono-server4
- Restart Apache:
- /etc/init.d/apache2 restart
- ------------------------------------------------------------------------------------------------
- test if working:
- 1. create test.aspx:
- sudo touch /var/www/test.aspx
- sudo nano /var/www/test.aspx
- add entry below, save, and browse in the browser:
- <%
- HelloWorldLabel.Text = "Hello, world!";
- %>
- <!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>Untitled Page</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <asp:Label runat="server" id="HelloWorldLabel"></asp:Label>
- </div>
- </form>
- </body>
- </html>
- 2. create test2.aspx:
- sudo touch /var/www/test2.aspx
- sudo nano /var/www/test2.aspx
- add entry below, save, and browse in the browser:
- <%@ Language=C# %>
- <HTML>
- <script runat="server" language="C#">
- void MyButton_OnClick(Object sender, EventArgs e)
- {
- MyLabel.Text = MyTextbox.Text.ToString();
- }
- </script>
- <body>
- <form id="MyForm" runat="server">
- <asp:textbox id="MyTextbox" text="Hello World" runat="server"></asp:textbox>
- <asp:button id="MyButton" text="Echo Input" OnClick="MyButton_OnClick" runat="server"></asp:button>
- <asp:label id="MyLabel" runat="server"></asp:label>
- </form>
- </body>
- </HTML>
- -----------------------------------------------------------------------------------------------
- test with simple database web application:
- install MySQL Connector/.Net driver:
- sudo apt-get install libmysql6.4-cil
- Creating a Database to Test the MySQL Connector(use phpmyadmin):
- CREATE DATABASE sample;
- USE sample;
- CREATE TABLE test (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(25));
- INSERT INTO sample.test VALUES (null, 'Lucy');
- INSERT INTO sample.test VALUES (null, 'Ivan');
- INSERT INTO sample.test VALUES (null, 'Nicole');
- INSERT INTO sample.test VALUES (null, 'Ursula');
- INSERT INTO sample.test VALUES (null, 'Xavier');
- create a test user named "testuser" and give that user access to the newly created sample database:
- CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'somepassword';
- GRANT ALL PRIVILEGES ON sample.* TO 'testuser'@'localhost';
- FLUSH PRIVILEGES;
- create a file called testdb.aspx in /var/www/mydotnetsite:
- <%@ 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>ASP and MySQL Test Page</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=127.0.0.1;Database=sample;User ID=testuser;Password=somepassword;Pooling=false;";
- MySqlConnection dbcon = new MySqlConnection(connectionString);
- dbcon.Open();
- MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT * FROM test", dbcon);
- DataSet ds = new DataSet();
- adapter.Fill(ds, "result");
- dbcon.Close();
- dbcon = null;
- SampleControl.DataSource = ds.Tables["result"];
- SampleControl.DataBind();
- }
- </script>
- </head>
- <body>
- <h1>Testing Sample Database</h1>
- <asp:DataGrid runat="server" id="SampleControl" />
- </body>
- </html>
- create a web.config file in /var/www/mydotnetsite(Please note that Custom Errors have been turned off in this web.config for debugging purposes. The customErrors mode line should be removed in a production environment.):
- <configuration>
- <system.web>
- <customErrors mode="Off"/>
- <compilation>
- <assemblies>
- <add assembly="MySql.Data"/>
- </assemblies>
- </compilation>
- </system.web>
- </configuration>
- -----------------------------------------------------------------------------------------------
- test with code behind sample:
- create source test3.aspx:
- sudo touch /var/www/mydotnetsite/test3.aspx
- sudo nano /var/www/mydotnetsite/test3.aspx
- add entry below, save.
- <%@ Page language="c#" src="test3.aspx.cs"
- Inherits="HelloApp.HelloPage" AutoEventWireup="true" %>
- <html>
- <head>
- <title>First Mono ASP.NET Application</title>
- </head>
- <body>
- <form runat="server">
- Enter your name: <asp:TextBox id="name" runat="server" />
- <asp:Button id="greet" Text="Greet" onClick="OnGreetClick" runat="server"/>
- </form>
- <br /><strong><asp:Label id="message" runat="server">Hello, World!
- </asp:Label></strong>
- </body>
- <html>
- create code behind test3.aspx.cs:
- sudo touch /var/www/mydotnetsite/test3.aspx.cs
- sudo nano /var/www/mydotnetsite/test3.aspx.cs
- add entry below, save.
- using System;
- using System.Web.UI.WebControls;
- namespace HelloApp
- {
- public class HelloPage : System.Web.UI.Page
- {
- protected Label message;
- protected Button greet;
- protected TextBox name;
- public void OnGreetClick(Object sender, EventArgs e)
- {
- message.Text = "Hello, " + name.Text;
- }
- }
- }
- -----------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment