下面是我试图通过实例化部分类以从单个 .aspx 页面中使用多个类(及其方法)的示例。
登录.aspx:
<%@ Page Language="C#" Codefile="Web_Code/LogonService.cs" Inherits="Client.LogonService" %>
<!-- html here, also will be calling methods here via a form -->
Web_Code/SessionHandler.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Client {
public partial class SessionHandler : Page {
//Constructor method here
public string setSessionUser(string username) {
return "this works, this is just a test";
}
}
}
Web_Code/LoginService.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Client {
public partial class LoginService : Page {
public void checkCredentials(object sender, EventArgs e) {
//Check credentials here
//If credentials are good, add the username to session
/* PROBLEM HERE: VS CAN'T FIND TYPE NOR INSTANTIATE*/
SessionHandler ses = new SessionHandler();
ses.setSessionUser(username.Value);
}
}
}
该问题在 Web_Code/LogonService.cs 中有注释 - 它无法实例化 SessionHandler。- 这是为什么?
我正在从 PHP 切换到 C#,在 PHP 世界中我会简单地输入“require(”Web_Code/SessionHandler.php“);” 并称它为一天,但 C# 的方式似乎更复杂一些。
我很感激任何意见!