Mikkel
Mikkel

Reputation: 1865

ASP.NET WebPages Custom Classes

I've been thinking if it's possible to create your own "classes", for example if I wanted to create a "Division" system under my Users table, would I be able to make a "class" I can use in my cshtml files which checks whether a certain user is a member of the division or not, without having to do the same query every time it needs to check?

For example for something like:

if (!Divisions.IsUserInDivision("division"))
{
    Response.Redirect("~/");
}

Thank you in advance.

Upvotes: 0

Views: 314

Answers (1)

Mike Brind
Mike Brind

Reputation: 30075

You can certainly add your own classes to a Razor Web Pages site. You must create an App_Code folder if you don't already have one and place them there.

public class Divisions
{

    public static bool IsUserInDivision(string division){
        // add your checking code here
    }
}

Upvotes: 2

Related Questions