在 Windows 窗体中,我可以使用以下代码创建一个名为“Authentication.cs”的类文件:
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 页面中。
任何帮助表示赞赏,
谢谢!