Precompiling your Visual Web Developer Asp.net Projects

For more information about LAMA servers, checkout:
LAMA – Best of ALL worlds tutorial

 

Precompiling Asp.net Web Projects
Visual Web Developer – Microsoft’s free version of Visual Studio, is a great tool to create quality Asp.net Sites.  VWD being free- does not include all the tools that Visual Studio does. In this case VWD does not include the option to precompile your web project.

Why Precompile?
Well – there are a couple reasons.  First, to remove all code in your project and place it in compiled DLL’s.

This may be a good option for those who host on a shared server.  That way your code is not placed in plain text on the server for others to see.

Next, to save server resources.  The first hit on the Asp.net server is when the Asp.net project is compiled.  If you precompile, then it saves those resources by not having to compile on the server.

Lastly, Mono’s vb compiler for Linux is a few steps behind the C# compiler.
If you have a LAMA server,  and like to use VB as your language.  You can precompile your site to ensure that it will work correctly.

Use The DoTheWeb.net Asp.net Precompiling tool!
You can use this handy GUI to precompile your websites.  DoTheWeb.net Asp.net Precompiler

NOTE: This is a ClickOnce Program, you may have to use Internet Explorer or Firefox to open it from the website.

A MySql Test site to for your LAMA Server

This is part of the LAMA – Best of all worlds tutorial
LAMA Tutorial Home Page

 

MySql Test Site with Visual Web Developer 2005

1.) Lets open up VWD, and create a new website called mysql-test-site

2.) Add the Mysql Connector/Net to the references.
Right click on the website name in Solution explorer, and choose Add Reference.

Select the MySql.Data from the list, and choose OK.

3.) Add a Data Grid View to the page.
In the Toolbox under Data, Select Grid View and drag it out onto the blank page.

4.) Your Code behind file should have the following code in it:

Imports System.Data

Imports MySql.Data.MySqlClient

Partial Class _Default

Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As ObjectByValAs System.EventArgs) HandlesMe.Load

‘The MySql Connection String:  replace IP address with the IP address of your LAMA server

Dim Conn As NewMySqlConnection(“server=192.168.1.37,database=testsite,Uid=aspnet,Pwd=aspnetpassword”)

Dim sSql As String = _

“Select * from phonebook”

Dim DA As New MySqlDataAdapter(sSql, Conn)

Dim DT As New DataTable

DA.Fill(DT)

Me.GridView1.DataSource = DT ‘set the datagrid to the datatable

Me.DataBind()

End Sub

End Class

 

5.) Run the project in VWD to make sure it works.  You should see a datagrid with our test data in it.

If you see John Doe, then its time to copy your project into your asp_net share and setup a test site for it.

Follow the instructions in the tutorial for copying and setting up the Asp.net site.

VB.net users: Make sure to precompile your sites before copying them to the LAMA server.

Tutorial – Configure Apache for Asp.net Site


Precompiling your Visual Web Developer Sites

Configuring MySql for your LAMA server and Visual Web Developer

 

This is part of the LAMA – Best of all worlds tutorial
LAMA Tutorial Home Page

MySql Connector .Net

MySql Connector/Net is the component that allows Asp.net to talk to Mysql Databases.

You will need this connector to be installed on the machine that has Visual Web Developer installed.
The latest version of MySql Connector is 5.2. 

Download the Widows Binary (ZIP) file from MySql Website:
http://dev.mysql.com/downloads/connector/net/5.2.html

1.)Unzip and go thru the Installer.  When it is completed, we will have to add the Assembly file to the LAMA Server.

2.)Navigate to the MySql Connector/Net folder inside Program Files.  This is usually:

C:\Program Files\MySQL\MySQL Connector Net 5.2.1

3.)Navigate into the Binaries\.NET 2.0\ folder.

You should see a MySql.Data.dll file.

4.)Copy that file into your asp_net share on your LAMA server.

5.)Now use Putty to connect to your LAMA server.

6.)Change to the asp_net directory

cd /asp_net

7.) Run the gacutil to install the MySql Assembly into Mono’s Global Assembly Cache

sudo gacutil -i MySql.Data.dll

You should see:

Installed MySql.Data.dll into the gac (/usr/local/lib/mono/gac)

 

Setting up a MySql user for Asp.net to use for web apps

Asp.net needs to have access to the MySql database for it’s web apps.  To allow this, we are going to setup a new user on the LAMA server.

1.) Use  Putty to connect to your LAMA server.

2.)Go into MySql.  You will need to know the root password if you set one during install.

sudo mysql -u root -p

It will ask for password, hit enter if you didnt use one

3.) From the Mysql command line, add a user for Asp.net

CREATE USER ‘aspnet’ IDENTIFIED by ‘aspnetpassword’;

This creates an aspnet user with a password of aspnetpassword
*This is for testing / demonstration purposes only.  For securing your mysql database please see MySql’s website for more information.

4.) Now we need to grant privileges to the user

GRANT ALL ON *.* TO ‘aspnet’@’%’ IDENTIFIED BY  ‘aspnetpassword’;

This grants all privileges to the aspnet user
*This is for testing / demonstration purposes only.  For securing your mysql database please see MySql’s website for more information.

 

Create a sample database

We will setup a simple database for testing.  We will make a simple phone book.

1.) Create the database,  from the Mysql command line type:

CREATE DATABASE testsite;

2.) Change to the testsite database

USE testsite;

3.) Create the phonebook table

CREATE TABLE `testsite`.`phonebook` ( `name` VARCHAR(50) NOT NULL, `number` VARCHAR(45) NOT NULL );

This will create a table (phonebook) with 2 fields: name, number

4.) Add a test record

INSERT INTO phonebook VALUES (‘John Doe’, ‘555-123-45678’);

 

One more thing about MySql:

By default MySql does not allow connections from outside computers.  They only allow connections from 127.0.0.1 (localhost).

If you want to test your connections to MySql on your LAMA server from your development machine, you will have to make a change to your MySql configuration file.

To do this:

1.) Use  Putty to connect to your LAMA server.

2.) change directory to the Mysql configuration directory.

cd /etc/mysql

3.) Make a copy of your my.cnf file

sudo cp my.cnf old_my.cnf

4.) Open my.conf in your editor

sudo pico my.cnf

5.) find the following line and comment it out:

            bind-address = 127.0.0.1
            
            change to :
            
            #bind-address = 127.0.0.1

6.) ctrl-x to exit, Y to save the file

7.) restart MySql

sudo /etc/init.d/mysql restart

Security note: This opens up your MySql server to anyone.  Please take all necessary precautions before making your LAMA server live on the internet. You can learn more about MySql security from the MySql web site.

Next in tutorial .. Create a MySql test site

Configuring Samba on your Ubuntu LAMA Server

 

This is part of the LAMA – Best of all worlds tutorial
LAMA Tutorial Home Page

Samba File Server

During your install of Ubuntu 8.04 server, one of the install options was Samba File server.  This allows you to setup “shares” on your Ubuntu LAMA server for easy file transfer from your Windows machine.

To setup Samba, we will be making changes to the smb.conf file, samba’s configuration file.

To get started:
Use Putty to connect to your LAMA server.

First lets make a directory that we can share, and set the group and permissions

sudo mkdir /asp_net
sudo chgrp admin /asp_net
sudo chmod g+w /asp_net

Now onto our smb.conf file:

1.) It is always best to make a copy of your existing smb.conf file – just in case.

cd /etc/samba/

 

sudo cp smb.conf old_smb.conf

2.)Open the smb.conf in your favorite text editor.  We will use pico.

sudo pico smb.conf

3.)Put the following lines at the end of the smb.conf file,  This will setup simple permissions for the admin group of Ubuntu server.  For more information on Samba configuration, see Samba’s web site.

            
    [asp_net]
           comment = Asp.net app folder
           path = /asp_net/
           read only = no
           valid users = @admin
           write list = @admin
           browseable = yes

4.) CTRL-X to close, Y to save the file

5.) Restart Samba

sudo /etc/init.d/samba restart

Setting up the User for Samba

Samba needs to know the password for your username.  This is the username that you setup during installation, by default Ubuntu puts your username in the admin group.

sudo smbpasswd {your username}

then it will ask you for your current password.

Then Samba should be ready.  To test, open up your network places and put \\{your-ubuntu-ip-address} in the address bar.

You should see asp_net folder.  Double click, and try to make a new folder in asp_net.
If you can, then you completed samaba configuration successfully.

If not check the smb.conf file for any mistakes, and restart samba. (sudo /etc/init.d/samba restart)

Next .. Setting up your Web Developer Studio for LAMA Sites

 

Installing Mono on your Ubuntu 8.04 LAMA Server

 

This is part of the LAMA – Best of all worlds tutorial
LAMA Tutorial Home Page

The Script

DoTheWeb.net has put together a script for you to help with your Mono source install.  With help fromSean’s Mental Walkabout Mono Script and some changes to make it Ubuntu specific.  This script will download all necessary software required to compile and install mono.

It will also download and install the mod_mono apache module, and setup your apache to recognize Asp.net websites.

This script is specific to Ubuntu 8.04LTS. It may work on other Ubuntu verisions but has not been tested.

To get started:
Use Putty to connect to your LAMA server.

Run the following commands from the Ubuntu command line:

1.)Download the script from DoTheWeb.net

sudo wget http://www.dotheweb.net/lama/monoinstall.sh

2.) Run the script

sudo sh monoinstall.sh

This will start alot of commands.  You will have to watch it for the first few minutes to tell the package manager to download needed packages.

When it is done downloading packages, it will go out to the internet and download the source files and compile.  This will take some time.  

At the end of the script, you should have a complete working LAMA server.

 

Next in tutorial: .. Setting up Samba File sharing to copy your windows files to your LAMA server