在Windows Forms中,我可以创建一个名为“Authentication.cs”的类文件,并使用以下代码:
在WebMatrix中,我可以插入一个名为“Authentication.cs”的新类文件,并插入上述代码。
在我的default.cshtml文件中,我这样做:
public class Authentication
{
public string Name;
internal bool Authenticate()
{
bool i = false;
if (Name == "Jason")
{
i = true;
}
return i;
}
}
在WebMatrix中,我可以插入一个名为“Authentication.cs”的新类文件,并插入上述代码。
在我的default.cshtml文件中,我这样做:
<body>
@{
Authentication auth = new Authentication();
if(auth.Authenticated("jasonp"))
{
<p>@auth.Authenticated("jasonp");</p>
}
}
</body>
但是它不起作用!它适用于WinForms桌面应用程序,但在WebMatrix中不适用。我不知道为什么它不起作用。错误信息是:
"命名空间Authenticate不存在。您确定已引用了程序集等吗?"
因此,在我的default.cshtml文件顶部,我尝试了以下内容:
@using Authentication.cs;
这导致了完全相同的错误!
我无法找到任何文件说明如何将一个类文件“包含”到您的WebMatrix页面中。
感谢您的任何帮助!
谢谢!