使用NetTiers生成底层时,抛出“Unable to load NetTiersServiceSection”异常

本文介绍了一种在使用NetTiers生成底层代码时遇到的UnabletoloadNetTiersServiceSection异常,并提供了详细的WEB.CONFIG配置示例,帮助开发者避免类似问题。

前阵子,使用NetTiers生成底层,新建项目。在还没写入代码时先行生成了一下,但却抛出“Unable to load NetTiersServiceSection”异常。一查,原来是WEB.CONFIG没有进行配置。

配置如下:

<configuration>
    <configSections>
        <section name="myNameSpace.Data" type="myNameSpace.Data.Bases.NetTiersServiceSection, myNameSpace.Data" allowDefinition="MachineToApplication" restartOnExternalChanges="true"/>
        <section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null"/>
        <section name="urlrewritingnet" requirePermission="false" type="UrlRewritingNet.Configuration.UrlRewriteSection, UrlRewritingNet.UrlRewriter"/>
        <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
            <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
                <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
                <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
                    <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere"/>
                    <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
                    <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
                </sectionGroup>
            </sectionGroup>
        </sectionGroup>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
        <section name="TinyMCE" type="Moxiecode.TinyMCE.ConfigHandler,Moxiecode.TinyMCE" requirePermission="false"/>
        <section name="TunynetHttpCompress" type="TunyNet.Web.HttpCompress.Configuration,TunyNet.Web.HttpCompress"/>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <section name="SpaceBuilder.Web.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
        </sectionGroup>
    </configSections>
    <appSettings/>
    <connectionStrings>
        <add name="ConnectionString" connectionString="server=.;database=XX;uid=dbsa;pwd=dbsa;"/>
    </connectionStrings>
    <myNameSpace.Data defaultProvider="SqlNetTiersProvider">
        <providers>
            <!--
                *** SqlClient Provider ***
                    connectionStringName: sqlclient connection string to the db
                    useStoredProcedure: if true, indicates that we use the stored procedures, otherwise, we use parametrized queries that are embedded.
            -->
            <add name="SqlNetTiersProvider" type="myNameSpace.Data.SqlClient.SqlNetTiersProvider, myNameSpace.Data.SqlClient" connectionStringName="myNameSpace.Data.ConnectionString" providerInvariantName="System.Data.SqlClient" entityFactoryType="myNameSpace.Entities.EntityFactory" useEntityFactory="true" enableEntityTracking="false" enableMethodAuthorization="false" useStoredProcedure="true" defaultCommandTimeout="30"/>
            <!--
                *** WebserviceClient Provider ***
                The url parameter indicates the webservices url (ex: http://localhost/myNameSpace/myNameSpaceServices.aspx)
                <add
                    name="WsNetTiersProvider"
                    type="myNameSpace.Data.WebServiceClient.WsNetTiersProvider, myNameSpace.Data.WebServiceClient"
                    url="/myNameSpaceServices.asmx" />
            -->
        </providers>
    </myNameSpace.Data>
    <system.web>
        <!--
            设置 compilation debug="true" 将调试符号插入
            已编译的页面中。但由于这会
            影响性能,因此只在开发过程中将此值
            设置为 true。
        -->
        <compilation debug="true" />
        <!--
            通过 <authentication> 节可以配置 ASP.NET 使用的
            安全身份验证模式,
            以标识传入的用户。
        -->
        <authentication mode="Windows" />
        <!--
            如果在执行请求的过程中出现未处理的错误,
            则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
            开发人员通过该节可以配置
            要显示的 html 错误页
            以代替错误堆栈跟踪。

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
    </system.web>
</configuration>

 

这只是我遇到的这个异常的时的情况,可能这个异常还会有其他的问题存在,因为我之前好像遇到过这种异常的另一种情况。

所以有其他资料时,我将进一步善。

### 无法加载证书的可能原因及解决方法 在尝试将 EFI 安全启动证书转换为 `.cer` 格式,如果遇到 `Unable to load certificate` 错误,可能是由以下几个原因导致的: #### 1. 证书文件内容不完整或格式错误 EFI 变量中存储的证书通常是 DER 编码的 X.509 证书,但这些数据可能包含额外的 UEFI 变量头信息,导致 `openssl` 无法直接解析。使用 `efivar` 导出的 `.raw` 文件可能包含非证书数据,需要先剥离额外的头信息[^1]。 可以使用以下命令提取原始 DER 证书内容: ```bash dd if=db.raw bs=1 skip=4 of=db.der ``` 其中 `skip=4` 表示跳过前 4 字节的 UEFI 变量属性头。之后再使用 `openssl` 转换: ```bash openssl x509 -inform der -in db.der -out db.cer ``` #### 2. 使用了错误的输入格式 如果使用 `openssl` 未指定 `-inform der` 参数,`openssl` 会默认尝试解析 PEM 格式,导致无法识别 DER 编码的数据[^1]。必须确保使用 `-inform der` 指定输入格式为 DER。 #### 3. 文件路径或权限问题 UEFI 变量文件位于 `/sys/firmware/efi/efivars/` 目录下,访问这些文件需要 root 权限。如果未使用 `sudo` 或等效权限执行命令,可能导致文件读取失败[^1]。 应使用以下方式访问: ```bash sudo efivar --name= --dump /sys/firmware/efi/efivars/db-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx > db.raw ``` #### 4. 文件损坏或未正确导出 在导出 EFI 变量,如果使用了不兼容的工具或命令参数错误,可能导致输出文件内容损坏或不完整。应使用 `efivar` 或 `get_machine_id` 等专为 EFI 变量操作设计的工具进行导出。 #### 5. 证书本身不是 X.509 格式 部分 EFI 变量中的证书可能不是标准的 X.509 证书,而是用于签名的公钥或哈希值。这种情况下,`openssl` 无法将其解析为标准证书格式。需要使用 `certutil` 或其他工具检查其实际结构。 --- ### 示例命令汇总 ```bash # 导出 EFI db 变量 sudo efivar --name= --dump /sys/firmware/efi/efivars/db-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx > db.raw # 剥离 UEFI 头部 dd if=db.raw bs=1 skip=4 of=db.der # 转换为 .cer 格式 openssl x509 -inform der -in db.der -out db.cer ``` --- ### 验证证书内容 转换完成后,可以使用以下命令查看 `.cer` 文件内容: ```bash openssl x509 -in db.cer -text -noout ``` 这将显示证书的详细信息,包括颁发者、有效期、公钥等,可用于确认证书是否正确解析。 --- ### 总结 在转换 EFI 安全启动证书遇到 `Unable to load certificate` 错误,通常与证书格式、头部信息、权限或工具使用不当有关。通过剥离 UEFI 头部、指定 DER 输入格式、使用管理员权限访问 EFI 变量文件等方法,可以有效解决该问题。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值