加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 如何使用Forms身份验证将用户重定向到特定页面

发布时间:2020-12-16 09:42:16 所属栏目:asp.Net 来源:网络整理
导读:我想配置应用程序并阻止用户直接访问应用程序中的任何页面而无需登录,但任何用户都可以访问网站主页. 但是当我运行主页,登录页面或网站的任何页面时,我收到此错误: – 无法访问请求的页面,因为页面的相关配置数据无效. 我无法找出我犯错误的地方.我发布了我
我想配置应用程序并阻止用户直接访问应用程序中的任何页面而无需登录,但任何用户都可以访问网站主页.

但是当我运行主页,登录页面或网站的任何页面时,我收到此错误: – 无法访问请求的页面,因为页面的相关配置数据无效.

我无法找出我犯错误的地方.我发布了我的web.config文件.看看它.看看我在哪里弄错了,解决方案是什么.

?web.config中

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application,please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>

  <connectionStrings>
    <add name="ConnectionString" connectionString="Data Source=(LocalDB)MSSQLLocalDB;AttachDbFilename=|DataDirectory|Database.mdf;Integrated Security=True"
        providerName="System.Data.SqlClient" />
  </connectionStrings>

  <authentication mode="Forms">
    
    <forms loginUrl="/Registration/LoginPage.aspx">
      
    </forms>
    
  </authentication>
  

    <system.web>
      <compilation debug="true" targetFramework="4.5.2" />
      <httpRuntime targetFramework="4.5.2" />
    </system.web>
  
  <location path="FIRST PAGE">
      <system.web>
        <authorization>
          <allow users="*"/>
          
        </authorization>
      </system.web>
    </location>
  
  <location path="Registration">
      <system.web>
        <authorization>
          <allow users="?"/>
          
        </authorization>
      </system.web>
    </location>
  
  
    <location path="AdminHome">
      <system.web>
        <authorization>
          <allow users="admin"/>
          <deny users="*"/>
        </authorization>
      </system.web>
    </location>
  
  <location path="Student">
      <system.web>
        <authorization>
          <allow roles="Student"/>
          <deny users="*"/>
        </authorization>
      </system.web>
    </location>
  
<location path="Teacher">
      <system.web>
        <authorization>
          <allow roles="Teacher"/>
          <deny users="*"/>
        </authorization>
      </system.web>
    </location>

  <appSettings>

    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
    
  </appSettings>
  

</configuration>

?错误

enter image description here

enter image description here

该网站的主页位于FIRST PAGE文件夹下,登录和注册页面位于文件夹Registration下

解决方法

< authentication>您的配置的一部分应该在< system.web>内.部分

MSDN authentication Element

只需编辑您的web.config:

<system.web>
   <authentication mode="Forms">
       <forms loginUrl="/Registration/LoginPage.aspx">
       </forms>
   </authentication>
   <compilation debug="true" targetFramework="4.5.2" />
   <httpRuntime targetFramework="4.5.2" />
</system.web>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读