Linux deploys the bumpy journey of the ASP. NET SQLite application. Sample code is attached at the bottom of the article.
There is an idle Linux VPS, trying to deploy a. NET program, the result is on the road to the pit, but in the end is a perfect solution to the problem, then recorded as follows.
Environment: Linux System for CentOS 6 mono version mono-3.2.1 Jexus version jexus-5.6.4
I. Installation Environment
1. Install Mono
Install the system environment first:
Yum-y install gcc gcc-c++ bison pkgconfig glib2-devel gettext make libpng-devel libjpeg-devel libtiff-devel libexif-devel Giflib-devel libx11-devel freetype-devel fontconfig-devel cairo-devel
Download Mono Installation:
wgethttp//download.mono-project.com/sources/mono/mono-3.2.1.tar.bz2Tar-JXVF mono-3.2.1.Tar. BZ2CD Mono-3.2.1./configure–prefix=/usr MakeThe following error occurs :/SRC/.LIBS/LIBEGLIB.A (LIBEGLIB_LA-GUNICODE.O): Infunction' Monoeg_g_get_charset ':/root/mono-3.2.1/EGLIB/SRC/GUNICODE.C:223: Undefined reference to ' Locale_charset ' collect2:LDReturned1Exit Status Make[4]: * * * [test-eglib] Error1 Make[4]: Leaving directory '/root/mono-3.2.1/eglib/Test ' Make[3]: * * * [all-recursive] Error1 Make[3]: Leaving directory '/root/mono-3.2.1/Eglib ' Make[2]: * * * [ALL] Error2 Make[2]: Leaving directory '/root/mono-3.2.1/Eglib ' Make[1]: * * * [all-recursive] Error1 Make[1]: Leaving directory '/root/mono-3.2.1 - Make: * * * [ALL] Error2Modify Eglib/config.hVIEglib/config.h will#defineHave_localcharset_h 1 replaced by #define HAVE_LOCALCHARSET_H 0 Make Make InstallMono–v This step shows that the message represents a successful installation
2. Installing Jexus
CD/tmpwget linuxdot.net/down/jexus-5.6. 4. Tar tar -zxvf jexus-5.6. 4. Tar . GZ CD Jexus-5.6. 4 sudo ./Install
Jexus Related configuration Description: http://www.linuxdot.net/bbsfile-3084
Two. Code section
There are two ways to make ASP. NET Operation SQLite on Linux.
Because Linux comes with a sqlite environment, there is no need to install the environment. Windows does not need to install SQLite, or download Sqlite3.dll.
This sample is developed using WebForm.
1. Using Mono's own Mono.Data.Sqlite
Use the same method as ADO. There is not much to be explained here.
Mainly in the Link string section "Version=3;data source={file Path}"
2. Using the Sqlite-net in NuGet (the final method is perfect)
Install-package sqlite-net
Github:https://github.com/praeclarum/sqlite-net
Wiki:https://github.com/praeclarum/sqlite-net/wiki
It can be developed after installation. The wiki explains some of the detailed usage.
I just realize a few simple additions and deletions to change the operation.
How to use:
// primary key plus self-increment Public int Get set; }
More methods See Wiki
Some basic code.
Public Partial classDemo:System.Web.UI.Page {PrivateSqliteconnection con =NULL; protected voidPage_Load (Objectsender, EventArgs e) { varPath = Server.MapPath ("~/app_data/demo.db"); Con=Newsqliteconnection (path); //con. Createtable<user> ();//Creating a table requires only one execution if(!string. IsNullOrEmpty (request["ID"]) {con. Delete<User> (request["ID"]); Response.Redirect ("demo.aspx"); } varcmd = con. CreateCommand ("SELECT * from User"); varList = cmd. Executequery<user>(); foreach(varIteminchlist) {Response.Write (string. Format ("{0}-{1}-{2} <a href= ' demo.aspx?id={3} ' > Delete </a><br>", item. Name,item. Password,item. Createtime,item.id)); } } protected voidbtnAdd_Click (Objectsender, EventArgs e) { varRand =NewRandom (). Next ( -,999); User User=NewUser (); User. Name="Ceshi"+Rand; User. PassWord="123456"+Rand; User. Createtime=DateTime.Now; Con. Insert (user);//Add DataResponse.Redirect ("demo.aspx"); } }
The final release program was uploaded to the VPS using WINSCP. Perfect for running on Linux.
Run:
The above system is identified as Linux.
Three. Summary
The ASP. NET MVC version 5.0 and above is not particularly well supported in Linux mono environments.
Jexus is case-sensitive and must be case-consistent.
Finally, thank the Internet for the selfless sharing of the predecessors. Special thanks for sharing the garden @ Zhang Shanyu.
Source Address: Https://github.com/linezero/sqlitedemo
Reference Link: http://www.cnblogs.com/shanyou/p/3322811.html
http://www.jexus.org/
http://www.linuxdot.net/
If you think this article is helpful to you, please click "Recommend", thank you.
Linux deployment ASP. The bumpy journey of the application with demo and source code