【发布时间】:2012-12-23 19:38:30
【问题描述】:
下面是我试图通过实例化部分类以从单个 .aspx 页面中使用多个类(及其方法)的示例。
login.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# 的方式似乎更复杂一些。
感谢您的任何意见!
【问题讨论】:
-
我遗漏了一些东西。一个问题。你在这里问什么?
-
您好,我编辑了 OP 以引用问题在我的代码中的位置。如果您查看我试图实例化 SessionHandler 的 Web_Code/LogonService.cs,它不会,我的问题是如何解决这个问题。谢谢。
标签: c# partial-classes