我要定义一个自定义用户控件UserCheck,用来验证用户是否已经登录,在UserCheck.ascx.cs的代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["loginName"] == null)
Response.Redirect("Login.aspx");
}
然后在Default.aspx中引用代码如下:
<%@ Register Src="UserCheck.ascx" TagName="UserCheck" TagPrefix="uc1" %>
<uc1:UserCheck id="UserCheck1" runat="server"> </uc1:UserCheck>
生成页成功。但在调试运行的时候出现错误:
:\Program Files\Microsoft Visual Studio 8\Common7\IDE> "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe" /t:library /utf8output /R:"C:\WINDOWS\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Runtime.Serialization\3.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Mobile\2.0.0.0__b03f5f7f11d50a3a\System.Web.Mobile.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\cjupload\43d8b639\1db5f78a\assembly\dl3\5904bd67\003bca0c_726cc701\Interop.Word.DLL" /R:"C:\WINDOWS\assembly\GAC\Microsoft.Vbe.Interop\12.0.0.0__71e9bce111e9429c\Microsoft.Vbe.Interop.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Services\2.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.WorkflowServices\3.5.0.0__31bf3856ad364e35\System.WorkflowServices.dll" /R:"C:\WINDOWS\assembly\GAC\stdole\7.0.3300.0__b03f5f7f11d50a3a\stdole.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\cjupload\43d8b639\1db5f78a\assembly\dl3\8fd51fb5\00dcb7e5_e32cc901\Interop.Excel.DLL" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel.Web\3.5.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.IdentityModel\3.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.DirectoryServices\2.0.0.0__b03f5f7f11d50a3a\System.DirectoryServices.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\cjupload\43d8b639\1db5f78a\App_Code.equgm76-.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\cjupload\43d8b639\1db5f78a\assembly\dl3\3a1acf4d\006d2d04_b9bfc801\Interop.Microsoft.Office.Core.DLL" /out:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\cjupload\43d8b639\1db5f78a\App_Web_usercheck.ascx.cdcab7d2.9istsihc.dll" /D:DEBUG /debug+ /optimize- /w:4 /nowarn:1659;1699;1701 "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\cjupload\43d8b639\1db5f78a\App_Web_usercheck.ascx.cdcab7d2.9istsihc.0.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\cjupload\43d8b639\1db5f78a\App_Web_usercheck.ascx.cdcab7d2.9istsihc.1.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\cjupload\43d8b639\1db5f78a\App_Web_usercheck.ascx.cdcab7d2.9istsihc.2.cs"
Microsoft (R) Visual C# 2005 编译器 版本 8.00.50727.1433
用于 Microsoft (R) Windows (R) 2005 Framework 版本 2.0.50727
版权所有 (C) Microsoft Corporation 2001-2005。保留所有权利。
f:\learning\JTVCS\CJUpload\UserCheck.ascx.cs(912305,33): error CS0115: “ASP.usercheck_ascx.FrameworkInitialize()”: 没有找到适合的方法来重写
然后在引用语句:
<uc1:UserCheck id="UserCheck1" runat="server"> </uc1:UserCheck>
下方出现一条红线,提示信息是:
引用时出现元素“UserCheck”不是已知元素。原因可能是网站中存在编译错误 。
为什么呢?
如果是项目,清理解决方案,重新生成解决方案。
如果是网站,转化为项目。
一般来说只要编译一次就不再提示了,这个BUG经常出现的,如果编译不通过或仍未消除此提示,则应检查一下头部声明。