简体   繁体   English

ASP.NET WebPages自定义类

[英]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? 我一直在考虑是否可以创建自己的“类”,例如,如果我想在Users表下创建“ Division”系统,我是否可以创建一个可以在cshtml文件中使用的“类”哪个会检查某个用户是否是该部门的成员,而不必在每次需要检查时都进行相同的查询?

For example for something like: 例如,类似:

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

Thank you in advance. 先感谢您。

You can certainly add your own classes to a Razor Web Pages site. 当然,您可以将自己的类添加到Razor网页站点。 You must create an App_Code folder if you don't already have one and place them there. 如果还没有一个App_Code文件夹,请将其放置在该文件夹中。

public class Divisions
{

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM