我正在尝试编写一个简单的身份验证。我还试图加快速度并通过 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/