[英]C# Class Inheritance Issue
因此,由於項目規模小以及保持精簡的總體意圖,因此我沒有使用母版頁。 因此,我想在一個簡單的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).
我在這種事情上還很新,我想知道出了什么問題以及正確的語法是什么。 謝謝!
只需更新類以從頁面派生:
public class CasLogin : Page
{
您的錯誤消息告訴您問題所在。 將類更改為此:
public class CasLogin : Page
它告訴您確切的問題所在:
編譯器錯誤消息:ASPNET:確保此代碼文件中定義的類與'inherits'屬性匹配, 並確保它擴展了正確的基類(例如Page或UserControl)。
public class CasLogin {}
擴展Page
還是UserControl
?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.