所以我没有使用母版页,因为项目的规模很小,而且总体上是为了保持精简。因此,我想在一个简单的 cs 文件中包含一个类并在同一页面上使用它。
// <copyright file="anon.cs" company="Anonymous">
// ;
// </copyright>
namespace cheese.pies.org
{
using System;
using System.IO;
using System.Net;
using System.Web;
using System.Xml;
/// <summary>
/// Class to process CAS authentication.
/// Based on solutions from CASE and Yale.
/// </summary>
public class CasLogin
{
/// <summary>
/// Address of university cas host
/// </summary>
private const string CasHost = "notimportant";
/// <summary>
/// Get the logged-in user's id or redirect them to login.
/// </summary>
/// <returns>
/// DirectoryID of logged in user
/// </returns>
public static string GetId()
{
...
}
...
}
其余的相当不重要。我相信这是一个基本的语法错误。
这是文件test.aspx,它使用了一个页面包含。
<% @Page Language="C#" Inherits="CasLogin" CodeFile="anon.cs" %>
<script language="C#" runat="server">
protected void Page_Load(object sender, EventArgs e) {
String directoryId = CasLogin.GetId();
FormsAuthentication.RedirectFromLoginPage(directoryId, false);
}
</script>
我得到的错误是:
Compiler Error Message: ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).
我对这种事情还很陌生,我想知道出了什么问题以及正确的语法是什么。谢谢!