Run ASP. NET 4 (lower) in Linux)

Source: Internet
Author: User

The opensuse 11.3 operating system has been configured in "Run ASP. NET 4 (medium) in Linux.

Now, go to the gnome terminal and run the ifconfig command to verify that the virtual IP address is the static address we allocated for it in the Broadband Router at the beginning.

ben@linux-nyhn:~> /sbin/ifconfigeth0      Link encap:Ethernet  HWaddr 08:00:27:51:5B:0B            inet addr:192.168.1.251  Bcast:192.168.1.255  Mask:255.255.255.0          inet6 addr: fe80::a00:27ff:fe51:5b0b/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:853 errors:0 dropped:0 overruns:0 frame:0          TX packets:807 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000           RX bytes:853227 (833.2 Kb)  TX bytes:90376 (88.2 Kb)lo        Link encap:Local Loopback            inet addr:127.0.0.1  Mask:255.0.0.0          inet6 addr: ::1/128 Scope:Host          UP LOOPBACK RUNNING  MTU:16436  Metric:1          RX packets:22 errors:0 dropped:0 overruns:0 frame:0          TX packets:22 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:0           RX bytes:1300 (1.2 Kb)  TX bytes:1300 (1.2 Kb)ben@linux-nyhn:~> sudo vim /etc/hosts

 

As shown above, use the vim editor to edit the/etc/hosts file and add a domain name ben.skyiv.com, as shown in:

 

Note that the IP address must be 127.0.0.1, but not 192.168.1.20. In the Windows Vista operating system of the host machine, enter the command prompt as an administrator. use NotePad to edit the c: \ windows \ system32 \ drivers \ etc \ hosts file and add the same domain name ben.skyiv.com, note that the IP address must be 192.168.1.0.1 instead of 127.0.0.1, as shown in:

 

Apache Software has been installed in the opensuse 11.3 operating system but has not been enabled, as shown below:

ben@linux-nyhn:~> sudo /sbin/service apache2 statusChecking for httpd2:                                              unused

 

Now, let's set Apache to boot with the system, and start it now:

ben@linux-nyhn:~> sudo /sbin/chkconfig -add apache2apache2                   0:off  1:off  2:off  3:on   4:off  5:on   6:offben@linux-nyhn:~> sudo /sbin/service apache2 startStarting httpd2 (prefork)                                            doneben@linux-nyhn:~> sudo /sbin/service apache2 statusChecking for httpd2:                                              running

 

Now let's open the ben.skyiv.com website in the Google browser of Windows Vista operating system on the host machine:

 

As shown in, Apache 2.2.15 is running on the Linux/Suse operating system. However, the website does not have any content.

In the opensuse operating system, Apache default files are stored in the/srv/www/htdocs directory.

 

The opensuse operating system has created a public_html directory for each user. For example, my user is the/home/BEN/public_html Directory, which is used to place the content of the user's website. You can use ben.skyiv.com /~ Here, Ben is my user name, as shown in:

 

It can be seen that this directory is empty and you need to put it in Dongdong. Then, let's write the next index.html:

ben@linux-nyhn:~> cd public_htmlben@linux-nyhn:~/public_html> vim index.html

 

Access ben.skyiv.com/~ again in Windows Vista /~ Ben webpage:

 

Now let's take a look at the mono version:

ben@linux-nyhn:~> mono --versionMono JIT compiler version 2.6.4 (tarball Mon Jul  5 13:53:45 UTC 2010)Copyright (C) 2002-2010 Novell, Inc and Contributors. www.mono-project.comTLS:           __threadGC:            Included Boehm (with typed GC and Parallel Mark)SIGSEGV:       altstackNotifications: epollArchitecture:  amd64Disabled:      noneben@linux-nyhn:~> ben@linux-nyhn:~> gmcs --versionMono C# compiler version 2.6.4.0

 

This version of Mono 2.6.4 is too low. Follow the instructions on the mono official download page to perform the following steps:

Ben @ Linux-nyhn: ~>Sudo zypper addrepo http://ftp.novell.com/pub/mono/download-stable/openSUSE_11.3 mono-stableInstalling source 'mono-stable' [done] repository 'mono-stable' successfully addedenabled: yesautorefresh: Nouri: http://ftp.novell.com/pub/mono/download-stable/openSUSE_11.3ben@linux-nyhn:~>Sudo zypper refresh -- repo mono-stableRetrieving repository 'mono-stable' metadata [done] is building 'mono-stable' to install source cache [done] specified repositories have been refreshed. Ben @ Linux-nyhn: ~>Zypper dist-upgrade -- repo mono-stable====================> Here is a long upgrade = Ben @ Linux-nyhn: ~>

 

The upgrade is complete. Check the mono version again:

ben@linux-nyhn:~> mono --versionMono JIT compiler version 2.8.1 (tarball Fri Nov 12 14:37:21 UTC 2010)Copyright (C) 2002-2010 Novell, Inc and Contributors. www.mono-project.comTLS:           __threadSIGSEGV:       altstackNotifications: epollArchitecture:  amd64Disabled:      noneMisc:          debugger softdebug LLVM:          yes(2.8svn-mono)GC:            Included Boehm (with typed GC and Parallel Mark)ben@linux-nyhn:~> dmcs --versionMono C# compiler version 2.8.1.0

 

The latest mono 2.8.1 version has been upgraded.

On the Apache mod_mono Configuration tool page, you can generate a configuration file for the Apache software required to run ASP. NET, as shown in:

 

The generated ben.skyiv.com. conf file is as follows:

<virtualhost *:80>  ServerName ben.skyiv.com  DocumentRoot /home/ben/www  # MonoServerPath can be changed to specify which version of ASP.NET is hosted  # mod-mono-server1 = ASP.NET 1.1 / mod-mono-server2 = ASP.NET 2.0  # For SUSE Linux Enterprise Mono Extension, uncomment the line below:  # MonoServerPath ben.skyiv.com "/opt/novell/mono/bin/mod-mono-server2"  # For Mono on openSUSE, uncomment the line below instead:  MonoServerPath ben.skyiv.com "/usr/bin/mod-mono-server2"  # To obtain line numbers in stack traces you need to do two things:   # 1) Enable Debug code generation in your page by using the Debug="true"   #    page directive, or by setting  in the   #    application's Web.config  # 2) Uncomment the MonoDebug true directive below to enable mod_mono debugging  MonoDebug ben.skyiv.com true    # The MONO_IOMAP environment variable can be configured to provide platform abstraction  # for file access in Linux.  Valid values for MONO_IOMAP are:  #    case  #    drive  #    all  # Uncomment the line below to alter file access behavior for the configured application  MonoSetEnv ben.skyiv.com MONO_IOMAP=all  #  # Additional environtment variables can be set for this server instance using   # the MonoSetEnv directive.  MonoSetEnv takes a string of 'name=value' pairs   # separated by semicolons.  For instance, to enable platform abstraction *and*   # use Mono's old regular expression interpreter (which is slower, but has a  # shorter setup time), uncomment the line below instead:  # MonoSetEnv ben.skyiv.com MONO_IOMAP=all;MONO_OLD_RX=1  MonoApplications ben.skyiv.com "/:/home/ben/www"  <location "/">    Allow from all    Order allow,deny    MonoSetServerAlias ben.skyiv.com    SetHandler mono    SetOutputFilter DEFLATE    SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png)$" no-gzip dont-vary  </location>  <ifmodule mod_deflate.c>    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript  </ifmodule></virtualhost>

 

The ben.skyiv.com. conf file must be stored in the/etc/apache2/CONF. d directory:

Ben @ BEN: ~>Ll/etc/apache2/CONF. dTotal 8-rw-r -- r -- 1 Ben users 2037 01-04 ben.skyiv.com. conf-RW-r -- 1 Root 1239 10-01 mod_mono.conf

 

Create the/home/BEN/WWW directory and restart the apache service:

ben@ben:~> mkdir wwwben@ben:~> sudo /etc/init.d/apache2 restartSyntax OKShutting down httpd2 (waiting for all children to terminate)      doneStarting httpd2 (prefork)                                         doneben@ben:~> 

 

Now let's create a website:

ben@ben:~> cd wwwben@ben:~/www> vim index.html

 

Visit the ben.skyiv.com website in the opensuse 11.3 operating system, as shown in:

 

Click "server information" and the error "The resource cannot be found" appears:

 

This is expected, because we have not compiled the info. aspx file yet. It can be seen that ASP. NET is in version 2.0.

Now, modify the/etc/apache2/CONF. d/ben.skyiv.com. conf file as follows:

ben@ben:~/www> sudo vim /etc/apache2/conf.d/ben.skyiv.com.conf

 

Change the mod-mono-server2 to a mod-mono-server4, as shown in. Then restart the apache service:

ben@ben:~> sudo /etc/init.d/apache2 restartSyntax OKShutting down httpd2 (waiting for all children to terminate)      doneStarting httpd2 (prefork)                                         doneben@ben:~> 

 

Then access the ben.skyiv.com/aspx/info.aspx webpage again:

 

It can be seen that ASP. NET 4 is already running.

 

Now, let's write the info. aspx program:

ben@linux-nyhn:~/www> mkdir aspx src binben@linux-nyhn:~/www> vim aspx/info.aspxben@linux-nyhn:~/www> vim src/info.aspx.csben@linux-nyhn:~/www> vim src/info.rsp

 

The content of the webpage file aspx/info. aspx is as follows:

01: <% @ page Language = "C #" inherits = "skyiv. Ben. Web. infopage" %> 02: <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 03: <HTML xmlns = "http://www.w3.org/1999/xhtml"> 04: 

 

The contents of the C # source code src/info. aspx. CS are as follows:

01: using system; 02: using system. data; 03: using system. web. ui; 04: using system. web. UI. webcontrols; 05: 06: namespace skyiv. ben. web07: {08: public class infopage: page09: {10: protected gridview dgmain; 11: 12: Public void page_load (Object sender, eventargs e) 13: {14: if (ispostback) return; 15: dgmain. datasource = getinfo (); 16: dgmain. databind (); 17:} 18: 19: datatable getinfo () 20: {21: datatable dt = new datatable (); 22: DT. columns. add ("project", typeof (string); 23: DT. columns. add ("content", typeof (string); 24: addrow (DT, "Operating System", environment. osversion); 25: addrow (DT, "Common Language Runtime Library", environment. version); 26: Return DT; 27:} 28: 29: void addrow (datatable DT, string name, object Value) 30: {31: datarow DR = DT. newrow (); 32: Dr [0] = Name; 33: Dr [1] = value. tostring (); 34: DT. rows. add (DR); 35:} 36:} 37 :}

 

Compile the src/info. RSP file as follows:

-out:../bin/info.dll-t:library-r:System.Data-r:System.Webinfo.aspx.cs

 

Then, compile with the following command:

ben@linux-nyhn:~/www> cd srcben@linux-nyhn:~/www/src> dmcs @info.rsp

 

After compilation is completed, the website running effect is shown in:

 

So far, we have successfully run ASP. NET 4 in the Linux operating system.

 

References
  1. MoD mono
  2. Apache mod_mono Configuration Tool
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.