Installing Lighttpd with Mono support

by kkikta 27. March 2011 18:55

Below are the steps I used to get mono and lighttpd installed on my Ubuntu 10.104 LTS node from linode.com.

First I installed lighttpd using aptitude:

user@li35-84:~$ sudo aptitude install lighttpd

Next I needed support for .Net 2.0

user@li35-84:~$ sudo aptitude install mono-fastcgi-server

Then I created the file /etc/lighttpd/conf-available/15-mono.conf and added the following text using VI

#Mono Stuff
# Add index.aspx and default.aspx to the list of files to check when a
# directory is requested.
index-file.names += (
        "index.aspx",
        "default.aspx"
)


### The directory that contains your Mono installation.
# The "bin" subdir will be added to the PATH and the "lib" subdir will be
# added to the LD_LIBRARY_PATH.
# For a typical system-wide installation on Linux, use:
var.mono_dir = "/usr/"
# For an installation in a user account (lighttpd need read/exec access):
#var.mono_dir = "/home/username/mono-1.2.6/"

### A directory that is writable by the lighttpd process.
# This is where the log file, communication socket, and Mono's .wapi folder
# will be created.
# For a typical system-wide installation on Linux, use:
var.mono_shared_dir = "/tmp/"
# For an installation in a user account (dir must exist and be writable):
#var.mono_shared_dir = "/home/username/lighttpd_scratch/"

### The path to the server to launch to handle FASTCGI requests.
# For ASP.NET 1.1 support use:
#var.mono_fastcgi_server = mono_dir + "bin/" + "fastcgi-mono-server"
# For ASP.NET 2.0 support use:
var.mono_fastcgi_server = mono_dir + "bin/" + "fastcgi-mono-server2"

### The root of your applications
# For apps installed under the lighttpd document root, use:
var.mono_fcgi_root = server.document-root
# For apps installed in a user account, use something like:
#var.mono_fcgi_root = "/home/username/htdocs/"

### Application map
# A comma separated list of virtual directory and real directory
# for all the applications we want to manage with this server. The
# virtual and real dirs. are separated by  a  colon.
var.mono_fcgi_applications = "/:."

Once the mono settings were created I created a file (25-domain.com.conf) for the virtually hosted domain enabeling mono.

        server.modules   += ( "mod_fastcgi" )

        $HTTP["host"] =~ "domain\.com$" {
        server.document-root = "/var/sites/domain.com"
        server.errorlog = "/var/log/lighttpd/domain.com/error.log"
        accesslog.filename = "/var/log/lighttpd/domain.com/access.log"
        fastcgi.server  = (
                ".aspx" => ((
                        "socket" => mono_shared_dir + "fastcgi-mono-server-domain",
                        "bin-path" => mono_fastcgi_server,
                        "bin-environment" => (
                                "PATH" => "/bin:/usr/bin:" + mono_dir + "bin",
                                "LD_LIBRARY_PATH" => mono_dir + "lib:",
                                "MONO_SHARED_DIR" => mono_shared_dir,
                                "MONO_FCGI_LOGLEVELS" => "Standard",
                                "MONO_FCGI_LOGFILE" => mono_shared_dir + "fastcgi.log",
                                "MONO_FCGI_ROOT" => "/var/sites/domain.com",
                                "MONO_FCGI_APPLICATIONS" => "/:/var/sites/domain.com"
                        ),
                        "max-procs" => 1,
                        "check-local" => "disable"
                ))
        )
        fastcgi.map-extensions = (
                ".asmx"   => ".aspx",
                ".ashx"   => ".aspx",
                ".asax"   => ".aspx",
                ".ascx"   => ".aspx",
                ".soap"   => ".aspx",
                ".rem"    => ".aspx",
                ".axd"    => ".aspx",
                ".cs"     => ".aspx",
                ".config" => ".aspx",
                ".dll"    => ".aspx"
        )
}

I had read quite a bit of documentation telling me that I should not map a particular extension and or use the fastcgi.max-extensions and just process everything but I found that doing so prevented web services (axd) files from processing. Next it was time to enable the config changes in lighttpd by linking the files into the conf-enabled folder.

user@li35-84:~$ sudo ln /etc/lighttpd/conf-available/15-mono.conf /etc/lighttpd/conf-enabled/
user@li35-84:~$ sudo ln /etc/lighttpd/conf-available/25-domain.com.conf /etc/lighttpd/conf-enabled/

At this point it was necessary to create the directories where logs would be stored.

user@li35-84:~$ sudo mkdir /var/log/lighttpd/domain.com
user@li35-84:~$ sudo chown -R www-data:www-data /var/log/lighttpd/domain.com

Then create the directory were the website files will be stored

user@li35-84:~$ sudo mkdir /var/sites/
user@li35-84:~$ sudo mkdir /var/sites/domain.com

Last restart lighttpd

user@li35-84:~$ sudo /etc/init.d/lighttpd restart

There ya go now you have a server capable of running Mono compatable applications like this blog.

Tags:

.NET | Blog | BlogEngine.NET | Mono | Ubuntu

Convert NUnit tests to Visual Studio Tests

by kkikta 4. December 2009 04:16
If your like me you have done some unit testing but your not crazy about writing tests for everything because well you could be writing functional code. I'm not gonna argue that testing isn't necessary or that you should do it all the time. Personally I have found it extremely useful especially when testing components that are not full fledged programs but find it to be a bit unnecessary in many situations.

So you have been using NUnit to do your tests and it works great but with Visual Studio 2010 (and i think 2008) Microsoft built in a testing framework that's available to users of Team System and Professional. So you figure if I'm converting my project then why not convert my tests as well. It makes sense especially since its a pain when I work with someone on a project and they don't know about NUnit and complain that they have to install it, add the reference and all that jazz. So I am putting together a list of steps to do the conversion below.

  1. Unload your test project from the solution.
  2. Open up your project file(.cspro) in notepad (or your text editor of choice.)
  3. Find the first section of xml containing the following tag <PropertyGroup>.
  4. Inside the <PropertyGroup> tag add the following:
    <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    1. {3AC096D0-A1C2-E12C-1390-A8335801FDAB} means test project.
    2. {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} means 2008 solution.
  5. Reload the project.
  6. Change your reference from nunit.framework to Microsoft.VisualStudio.QualityTools.UnitTestFramework
  7. Add the following to you test classes
    using Microsoft.VisualStudio.TestTools.UnitTesting;
  8. Remove NUnit's names space from the classes (using NUnit.Framework;)
  9. Make the following changes to your class and method attributes:
    1. [TestFixture] becomes [TestClass]
    2. [TestFixtureSetUp] becomes [ClassInitialize]
    3. [TestFixtureTearDown] becomes [ClassCleanup]
    4. [SetUp] becomes [TestInitialize]
    5. [Test] becomes [TestMethod]
    6. [TearDown] becomes [TestCleanup]
  10. Close the solution and reopen it.

So far that seems to be about it. All in all a pretty easy change. If I find more I'll update. Also there is a tool that is supposed to do the conversion for you here but I prefer to know whats happening vs. using a tool blindly.

Tags:

.NET | General

jQuery Picklists Plugin (update)

by kkikta 8. October 2009 21:25

A couple of days ago I found a pretty cool jQuery plugin for doing two select boxes called picklists. I started using it but immediately noticed one feature was missing from it, when the list is loaded it doesn't load "selected" items into the second list. First I tried to hack some code to move the stuff and although I got it working I decided that wasn't really the right solution. Anyway I've add the setting "preload". When its true items that are selected at the time picklist plugin is loaded are added to the selected list so now its a pretty cool tool for .net/cf/php/etc. When the setting is false it does the same as it did before (the selected items list is blank). Anyway enjoy! ;P

 jquery.picklists.js (4.75 kb)

Tags:

.NET | ColdFusion | General | JavaScript

Report Viewer 2005 SP1

by kkikta 10. December 2008 15:29

Yesterday I was loading out a new version of some code on a new server and found out that the report viewer was having an error. There were multiple problems but the biggest to were the missing DLL's in the GAC which are in the attached file and missing directory permissions on the c:\windows\temp folder. Below are the error messages and the solution of each.

  1. Error Message: Microsoft.Reporting.WebForms.LocalProcessingException: An error occurred during local report processing. ---> Microsoft.Reporting.DefinitionInvalidException: The definition of the report 'Main Report' is invalid. ---> Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: An unexpected error occurred while compiling expressions. Native compiler return value: ‘[BC2001] file 'C:\WINDOWS\TEMP\nkty97-c.0.vb' could not be found’.

    Solution: Locate the windows temp directory (c:/windows/temp) and give the user (ASPNET) that's running the AppPool modify access to the folder.

  2. Error Messages:
    • System.Web.HttpCompileException: d:\somepath\Reports.aspx.cs(127): error CS0117: 'Microsoft.Reporting.WebForms.ReportViewer' does not contain a definition for 'Reset'
    • System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. File name: 'Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

    Solution: Register the following dll's in the GAC, they can generally be found at "C:\Program Files\Microsoft Visual Studio 8\ReportViewer"
    1. Microsoft.ReportViewer.Common.dll
    2. Microsoft.ReportViewer.WebForms.dll
    3. Microsoft.ReportViewer.WinForms.dll

    This can be done using the following command "gacutil /if <file>". gacutil.exe and gacutil.exe.config can be found at "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin"

    Once this is done restart IIS and you should be done. Also for convenience the files are attached.

ReportViewer.zip (1.50 mb)

Tags:

.NET | General

SQL Injection

by kkikta 29. August 2008 05:15
Recently a old client I use to do some consulting for called me up because their in-house development team was having problems stopping SQL Injection. I did the polite thing and attempted to explain how it could be fixed. They then asked me what it would cost for me to fix their cold fusion and SQL Server code. I sent them over a rate sheet and I have yet to hear back that was about 3-4 weeks ago. Guess they didn't like the price ;P

Anyway fast forward one of my friends was browsing my sites (.NET) and ran across an error in which it appeared Npgsql stated there were no more connections in the pool (woops forgot to turn on custom errors). Anyway I decided to see if this was happening alot so I opened up event viewer. What did I find someone was trying to attack my site with the same type of script. So I ran a few quick tests to confirm that my stored proc's are not vunerable. Then i got to thinking even if they were I implement at least a dual password system where one account (read-only) is used for select queries and another (read-write) is used for everything else so I figured I am pretty safe. Never mind that the script is targeting SQL Server and my projects are running on PostgreSQL. Needless to say I decided to let it go since who ever is attempting to attack me is just spinning their wheels and maybe as long as they are going after me they wont find someone who is vunerable.

In any case I find the whole situation mildly amusing.



I cannot stress enough sanatize your inputs and consider setting up different user accounts so that in case you forget to to protect something you limit what an attacker can do.

Tags:

.NET | ColdFusion | General | PostgreSQL

Paging for a .NET Repeater, DataList

by kkikta 9. May 2008 17:19

Anyone who knows anything about asp.net knows that the builtin paging functionality is pretty weak. In particular for datalist and repeaters its non-existant. So when I was asked to take a look at some paging functionality a co-worker designed the other day I thought might as well. I having designed one for coldfusion quite a long time ago have a pretty good understanding on how most people think it should work. Anyway right away I had problems with what the guy had designed it was good for small sets but would have been a nightmare to use on something over 20 pages. So I explained to him my thoughts on what it should do and showed the stuff I built, he agreed that what I showed him would be easier to use. So as he set off on modifying his coded I figured might as well take a look and see if anyone has anything prebuilt. The first couple things I found were unimpressive but then I stumbled upon this one from CodeProject was exactly what I was looking for (almost). I downloaded it implemented it looked at it sent an email to the author just to make sure there wasn't some crazy license on it and proceeded to thank him. That was not the end though the page I was playing with has some ajax modals on it which was causing the control to lose its state since only a few variables used viewstate in this control so I generated a small patch to fix this problem.

CutePager.patch (5.19 kb)

Tags:

.NET | General

Modifying controls in EditTemplate prior to display.

by kkikta 1. April 2008 20:19

Today I was working with a few items in an edit template and ran into a situation where I needed to disable one of the controls based on information in another control. I quickly found that this can't really be done with an onload or in the design. I eventualy tied a function to the OnDataBinding and was able to disable a text box. The reasoning for this is that the EditTemplate is not available until the control is in "Edit" mode.

Ex.

<asp:DataList id="dlTest" onEditCommand="dlTest_EditCommand" onUpdateCommand="dlTest_UpdateCommand">
    <EditTemplate>
        <asp:HiddenField id="hdfEditCritera" runat="server" value='<%# DataBinder.Eval(Container.DataItem, "TestCritera") %>' />
        <asp:TextBox ID="txtEditTest" OnDataBinding="TextBox_Enabled" runat="server" text='<%# DataBinder.Eval(Container.DataItem, "TestData") %>' />
    </EditTemplate>
    <ItemTemplate>
        <asp:Lable ID="lblText" runat="server" text='<%# DataBinder.Eval(Container.DataItem, "TestData") %>' />
        <asp:LinkButton id="lnkEdit" runat="server" CommandName="Edit" text="Edit" />
    </ItemTemplate>
</asp:DataList>

<%
    protected void TextBox_Enabled(object sender, EventArgs e)
    {
        DataListItem EditItem = dlTest.Items[dlTest.EditItemIndex];
        if (((HiddenField)EditItem.FindControl("hdfEditCritera")).Value.StartsWith("Test", StringComparison.InvariantCultureIgnoreCase))
            ((TextBox)EditItem.FindControl("txtEditTest")).Enabled = true;
        else
            ((TextBox)EditItem.FindControl("txtEditTest")).Enabled = false;
    }
%>

In this example if the hidden field started with "test" then the textbox would be enabled if not the its disabled.

Tags:

.NET

HTML textbox editors for .NET

by kkikta 24. January 2008 06:04
Rarely do you find "Free" software that does not require either several steps to setup or custom tweaks to get working the way you want to. For the past couple months I have been playing with FCKEditor which is nice don't get me wrong but its not the easiest to setup for some people (hence why I have had to do it for a few people). Once its working its great and couldn't be easier. That being said I have now found a tool that I believe is even better since it requires almost no setup at all. That tool is FreeTextBox, now I havn't tested any of the advance features but I have to say I do like that everything is contained in the library (images, javascript, etc.). It makes using this component a breeze I am definately going to see what it will take to get OpenFlashChart.NET to have similar functionality, I know its not difficult but it I just haven't done it before.

Tags:

.NET

C# Implementation of phk's md5crypt used for passwords in FreeBSD

by kkikta 23. January 2008 06:13

I wrote this a while ago with the intention of releasing it but never could find out where it would fit best. Anyway its a .NET implementation of Poul-Henning Kamp md5crypt routine for generating passwords. I personally am using it for creating passwords in a PostgreSQL database that is being used by a FreeBSD mail server. Its pretty easy to use and pretty safe too, word on the street is this is the same routine that cisco uses to encrypt passwords on routers and obviously its still used to create passwords in FreeBSD.

Koolwired.Cryptography.zip (4.82 kb)

Since its a static method in a static object there is no need to create an instance of the class just call it as such:

string newpass = Koolwired.Cryptography.md5crypt.crypt("password");

The example above creates a new password, this can also be used to verify existing passwords once you know the "salt/magic". The format is for this type of password is $[magic]$[salt]$[encrypted password] so its pretty easy to seperate. If you didn't know one if the benefits of salt is that two users could have the exact same passwords but the encrypted passwords would be different because the most likely do not have the same salt string.

string
verify = Koolwired.Cryptography.md5crypt.crypt("password", "$1$salt");



Tags:

.NET

Month List

Page List