C# making custom classes

So how do you create a custom class file in asp without using visual studio or similare to compile your .dll?
Well, all you need to do is to make a c# class like below. And then compile it to a dll file. If you are using IIS, place the dll in a bin folder in your project folder.

if you use the root folder it would be:


Compiling the dll is easy, but you need the following:

1. Download Microsoft.Net framework SDK v2.0
2. Locate the installation shortcuts in start menu, and open the SDK command prompt. Browse to the C:\inetpub\wwwroot\ and type in csc /target:library SqRtCustom.cs
3. move the SqRtCustom.cs in the bin folder
4. launch the aspx from ISS using adress localhost/index.aspx in your fav browser

The SqRtCustom.cs class file:

using System;
public class SqRtCustom {
  public SqRtCustom(double nr) {
     number = nr;

  private bool isPos(){
    if(number >= 0){
       return true;
    } else {
    return false;

public double sqRoot() {
    return Math.Sqrt(this.number);
  } else {
       throw new Exception("Cannot take the square root of a negative nr!");
private double number;

The index.aspx file:

<title>Let's do some math</title>
<script runat = "server">
  protected void Page_Load(object Source, EventArgs E){
    SqRtCustom[] test = new SqRtCustom[3];
    test[0] = new SqRtCustom(-16);
    test[1] = new SqRtCustom(0);
    test[2] = new SqRtCustom(25);
    Response.Write("<h1>Square root of a nr:</h1><hr />");
    for(int i = 0; i < test.Length; i++){
            Response.Write("<li>" + test[i].sqRoot() + "</li>");
        } catch(Exception error){
            Response.Write("<li>" + error.Message + "</li>");

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s