我正在从 PHP 迁移到 ASP.NET/C#。到目前为止一切顺利,但我不明白如何在 ASP.NET C# 类页面中实例化一个类。
例如我有 login.aspx:
<%@ Page Language="C#" Inherits="Portal.LoginService" src="LoginService.cs" %>
<!DOCTYPE html>
<body>
<form runat="server" id="login" name="login">
<p>Username:</p><input type="text" id="username" name="username" runat="server" />
<p>Password:</p><input type="password" id="password" name="password" runat="server" />
<input type="submit" name="submit" OnServerClick="Post_Form" runat="Server" />
</form>
</body>
登录服务.cs:
using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;
namespace Portal {
public class LoginService : Page {
protected HtmlInputControl username, password;
public void Post_Form(object sender, EventArgs e) {
if (username.Value != "" && password.Value != "") {
//LOGIC HERE
//This doesn't work
CustomSanitize a = new CustomSanitize();
}
}
}
}
CustomSanitize.cs:
using System;
namespace Portal {
public class CustomSanitize {
//instantiate here
public string sanitizeUserPass() {
return "logic here"
}
}
}
换句话说,我想将来自不同类的方法与我用 ASP.NET C# 设置的类一起使用。到目前为止,命名空间对我不起作用。
感谢您的任何意见。