如何从 web.config 指定 CodeFileBaseClass? [英] How do i specify CodeFileBaseClass from web.config?

查看:18
本文介绍了如何从 web.config 指定 CodeFileBaseClass?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i1 正在 web.config 中注册一个 用户控件 Control:

i1 am registering a user control Control in web.config:

<configuration>
    <system.web>
       <pages validateRequest="false">
          <controls>
              <add src="~/GenericControls/Toolbar.ascx" 
                    tagName="Toolbar" tagPrefix="Vista" />
          </controls>
       </pages>
    </system.web>
<configuration>

现在,因为我的 用户控件"Control,而不是 UserControl(为了支持模板),这会导致Visual Studio 错误:

Now, because my "user control" is a Control, rather than a UserControl (in order to support templating), this causes the Visual Studio error:

ASPNET:确保此代码文件中定义的类与继承"属性匹配,并且它扩展了正确的基类(例如 Page 或 UserControl).

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).

此错误的修复方法是您必须提醒 Visual Studio *control继承自Control`:

The fix for this bug is that you have to remind Visual Studio that the *controlinherits fromControl`:

<%@ Page language="c#" Inherits="University.AspNet.Index"  
      CodeFile="Index.aspx.cs" CodeFileBaseClass="XXXXXX" %>

具有超级机密的 CodeFileBaseClass 属性.除了我没有使用 Page 指令外,我在 web-config 中注册了 site-wide 控件:

with the super-secret CodeFileBaseClass attribute. Except i'm not using a Page directive, i'm registering the control site-wide in web-config:

<add src="~/GenericControls/Toolbar.ascx" 
      tagName="Toolbar" tagPrefix="Vista" />

如何在 web.config 中指定 CodeFileBaseClass?

这个问题是 Stackoverflow 系列中的一个,模板化用户控件":

This question is one in the ongoing Stackoverflow series, "Templating user controls":

推荐答案

试试这个:

<system.web>
    <!-- ... -->
    <pages pageBaseType="MyWeb.UI.MyPageBase" />
    <!-- ... -->
</system.web>

另外,请参考以下链接:

http://blogs.msdn.com/b/tom/archive/2008/08/22/known-issues-for-asp-net-with-net-3-5-sp1.aspx

http://forums.asp.net/t/1305800.aspx

建议的解决方法:

如果不是所有页面都需要 pageBaseType 类(例如 MyBasePage),您可以将其从 web.config 文件中删除,或者

If the pageBaseType class (for example, MyBasePage) is not needed for all pages, you can remove it from the web.config file, or

如果页面确实需要 pageBaseType 值,请修改代码隐藏文件中的类以扩展基本类型.在 filename.aspx.cs 代码隐藏文件中,确保该类继承自 web.config 文件中指定的 pageBaseType(例如,公共部分类 CodeFileClass : MyBasePage 而不是公共部分类 CodeFileClass : System.Web.UI.Page).

Where pages do require the pageBaseType value, modify the classes in the code-behind files to extend the base type. In the filename.aspx.cs code-behind file, make sure that the class inherits from the pageBaseType that is specified in the web.config file (for example, public partial class CodeFileClass : MyBasePage instead of public partial class CodeFileClass : System.Web.UI.Page).

另一种解决方法将允许您将以下属性添加到您的页面指令:

An alternative workaround will allow you to add the following attribute to your page directive:

CodeFileBaseClass="System.Web.UI.Page"

这篇关于如何从 web.config 指定 CodeFileBaseClass?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆