using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections;
using System.IO;/// <summary>
/// ST_ModuleBase 的摘要描述
/// </summary>
public class ST_ModuleBase
{
    private String basePathPrefix;
    //标识是否验证
    private bool authenticated;
    //basePathPrefix属性用来获取ST_PageBase.UrlBase的值
    /// <summary>
    /// 设置应用程序的虚拟程序根路径的网址
    /// </summary>
    public String PathPrefix
    {
        get
        {
            if (null == basePathPrefix && HttpContext.Current != null)
            {
                basePathPrefix = ST_PageBase.UrlBase;
            }
            return basePathPrefix;
        }
        set
        {
            basePathPrefix = value;
        }
    }
    /// <summary>
    /// Authenticate属性用来获取ST_PageBase.CheckUser方法的返回值
    /// </summary>
    /// <param name="name">用戶名(字串)</param>
    /// <param name="pwd">密碼(字串)</param>
    /// <returns>返回一個布爾值,帳號存在為true,否則為false</returns>
    public bool Authenticate(String name, String pwd)
    {
        //验证用户是否存在
        authenticated = ST_PageBase.CheckUser(name, pwd);
        return authenticated;
    }
}
類代碼
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class WebUserControl_ST_LogonModule : ST_ModuleBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //如果用戶已經登錄
        if (HttpContext.Current.User.Identity.IsAuthenticated)
        {
            String ST_UserName = HttpContext.Current.User.Identity.Name;
            ShowMsg.Text = "<b><font color='red'>" + ST_UserName + "</font></b>,歡迎您使用本系統!";
            ShowMsg.Style["color"] = "Green";
        }
        else
        {
            ShowMsg.Text = "您還未登錄本系統,登錄后才可以使用各項服務";
            ShowMsg.Style["color"] = "Red";
        }
    }
    protected void LoginButton_Click(object sender, EventArgs e)
    {
        //判斷用戶是否合法
        if (Authenticate(LogonNameTextBox.Text.Trim(), LogonPasswordTextBox.Text.Trim()) == true)
        {
            //System.Web.Security.FormsAuthentication.SetAuthCookie(用戶名稱,false);
            FormsAuthentication.SetAuthCookie(LogonNameTextBox.Text.Trim(), false);
            Response.Redirect(PathPrefix + "/ST_default.aspx");
        }
        else
        {
            MismatchLabel.Visible = true;
        }
    }
}
用戶自定義控件中的代碼,繼承了ST_ModuleBase.cs
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="exercise.aspx.cs" Inherits="_exercise" %>
<%@ Register Src ="~/WebUserControl/ST_LogonModule.ascx" TagName="LogonModule" TagPrefix="ucl" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>未命名頁面</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <ucl:LogonModule id="LogonModule" runat="server"></ucl:LogonModule>
    </div>
    </form>
</body>
</html>然後在一個頁面中調用了這個用戶自定義控件,可是爲什麽會提示請確定此程式碼檔中定義的類別符合 'inherits' 屬性,且其延伸正確的基底類別 (例如 Page 或 UserControl)。

解决方案 »

  1.   


    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="exercise.aspx.cs" Inherits="_exercise" %> 
    _exercise 要和EXERCISE.ASPX.CS里面的类 保持一致,如果有命名空间,还要加上命名空间
      

  2.   

    建议贴出 exercise.aspx.cs 这个里面的代码
      

  3.   

    如果这两个页面没有问题,那么还请检查下  ="~/WebUserControl/ST_LogonModule.ascx 这个控件里面的ASCX页面的INHERITS 的类名和ASCX.CS里面的是否一致...
    GOOD LUCK ,如果还不行的话, 我可以帮忙调试~~
      

  4.   


    <%@ Page Language="C#" MasterPageFile="~/Controls/MISMaster.Master" AutoEventWireup="true" CodeBehind="SelectProduct.aspx.cs" Inherits="WebUI.Product.SelectProduct" Title="商品查询" %>前面要加上那个程序集名,要是是放在文件下面,还要.下文件!!!
      

  5.   

    这个里面没写代码,我就在用户自定义控件中写的,然后在exercise页面中前台直接调的那个用户自定义控件