0

所以我没有使用母版页,因为项目的规模很小,而且总体上是为了保持精简。因此,我想在一个简单的 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).

我对这种事情还很陌生,我想知道出了什么问题以及正确的语法是什么。谢谢!

4

3 回答 3

4

只需更新类以从页面派生:

public class CasLogin : Page
{
于 2012-05-01T18:56:40.883 回答
0

您的错误消息告诉您问题所在。将类更改为:

public class CasLogin : Page
于 2012-05-01T18:57:42.360 回答
0

它准确地告诉你出了什么问题:

编译器错误消息:ASPNET:确保此代码文件中定义的类与“继承”属性匹配,并且它扩展了正确的基类(例如 Page 或 UserControl)。

是否public class CasLogin {}扩展PageUserControl

于 2012-05-01T18:57:48.807 回答