c# - 无法识别的元素 'authentication' 。

标签 c# asp.net

我正在尝试编写一个简单的身份验证。我还试图加快速度并通过 web.config 了解表单例份验证。

因此,如果我将“用户名”和“密码”硬编码到 C# 代码中并执行一个简单的条件,我的身份验证就会正常工作。

但是,我收到错误消息“无法识别的元素‘身份验证’。

Line 2:     <system.web>
Line 3:         <customErrors mode="off">
Line 4:             <authentication mode="Forms">
Line 5:                 <forms name=".C#FEWD" 
Line 6:                     loginUrl="/schools/admin/login/index.aspx" 

我的 web.config 文件如下所示:

<configuration>
    <system.web>
        <customErrors mode="off">
            <authentication mode="Forms">
                <forms name=".C#FEWD" 
                    loginUrl="/schools/admin/login/index.aspx" 
                    protection="All" 
                    timeout="60">
                    <credentials passwordFormat="Clear">
                        <user name="schools" password="magic" />
                    </credentials>
                </forms>
            </authentication>
        <authorization>
            <deny users="?" />
        </authorization>
        </customErrors>
    </system.web>
</configuration>

最佳答案

这可能只是您在 customErrors 设置中缺少节点终止符:

<customErrors mode="off"/>

更多以下评论:

您的完整配置应该是:

<configuration>
    <system.web>
        <customErrors mode="off" />
        <authentication mode="Forms">
            <forms name=".C#FEWD" 
                loginUrl="/schools/admin/login/index.aspx" 
                protection="All" 
                timeout="60">
                <credentials passwordFormat="Clear">
                    <user name="schools" password="magic" />
                </credentials>
            </forms>
        </authentication>
        <authorization>
            <deny users="?" />
        </authorization>
    </system.web>
</configuration>

关于c# - 无法识别的元素 'authentication' 。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9131953/

相关文章:

javascript - 如何发送带有公式字段的handsontable

c# - 使用 sql 连接的最佳/标准方法是什么?

asp.net - 服务不在 Docker 中进行内部通信

c# - 如何将运行时的测试用例结果调用到另一个文件以更新 testRail 中的测试用例结果?

c# - Linq-to-SQL 检索子表抛出 InvalidCastException

c# - 是否可以针对多个身份验证提供程序来保护 ASP.NET Web API 2 应用程序的安全?

jquery - ASP.net 中隐藏在覆盖层后面的模态 jQuery 对话框

c# - 与 Tibco spotfire 集成的系统

javascript - 下拉宽度在 IE 11 中自动增加

c# - 有什么可以用 C# 事件做而不能用 VB 事件做的事情吗?