用户未经过身份验证时,管理员文件夹中的页面不会重定向到登录页面(Windows窗体身份验证)

时间:2022-12-03 21:50:58

I'm new to asp.net, so any pointers would be great my main web.config code which connects to a sql database from godaddy.

我是asp.net的新手,所以任何指针都会很棒我的主web.config代码连接到godaddy的sql数据库。

<configuration>
  <connectionStrings>
    <add name="XXXXXX" connectionString="Data Source=XXXXXX; Initial Catalog=AllMobileDB; User ID=XXXXXX; Password=XXXXXX@;" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.web>
    <roleManager enabled="true"/>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
      </assemblies>
    </compilation>
    <authentication mode="Forms">
      <forms loginUrl="login.aspx"/>
    </authentication>
    <membership defaultProvider="SqlProvider">
      <providers>
        <clear/>
        <add connectionStringName="XXXXXX" applicationName="/" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Hashed" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" name="SqlProvider" type="System.Web.Security.SqlMembershipProvider"/>
      </providers>
    </membership>
  </system.web>
  <system.net>
    <mailSettings>
      <smtp from="XXXXXX">
        <network enableSsl="true" host="smtp.gmail.com" userName="XXXXXX" password="XXXXXX" port="25"/>
      </smtp>
    </mailSettings>
  </system.net>
</configuration>

I have a folder called admin and a page called adminpage i set up username and folder access via Web Site Administration Tool

我有一个名为admin的文件夹和一个名为adminpage的页面我通过网站管理工具设置了用户名和文件夹访问权限

my web.config in my admin folder code

我的管理文件夹代码中的web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
        <authorization>
            <allow roles="Adminstator" />
            <deny users="*" />
        </authorization>
    </system.web>
</configuration>

it should let only people who is signed in to view the page however as of right now any one can access it. Any idea how to fix this thank you.

它应该只允许登录的人查看页面,但是现在任何人都可以访问它。任何想法如何解决这个谢谢你。

3 个解决方案

#1


0  

Set the location element

设置位置元素

<system.web>
    <authentication mode="Forms">
      <forms loginUrl="Admin/login.aspx" defaultUrl="Admin/default.aspx"/>
    </authentication>
  <authorization>
    <allow users="*"/>
  </authorization>
</system.web>

<location path="Admin">
  <system.web>
   <authorization>
    <deny users="?"/>
   </authorization>
  </system.web>
</location>

#2


0  

Try changing deny element to question mark:

尝试将deny元素更改为问号:

    <authorization>
        <allow roles="Adminstator" />
        <deny users="?" />
    </authorization>

#3


0  

Try spelling Administrator correctly:

尝试正确拼写管理员:

<allow roles="Administrator" />

#1


0  

Set the location element

设置位置元素

<system.web>
    <authentication mode="Forms">
      <forms loginUrl="Admin/login.aspx" defaultUrl="Admin/default.aspx"/>
    </authentication>
  <authorization>
    <allow users="*"/>
  </authorization>
</system.web>

<location path="Admin">
  <system.web>
   <authorization>
    <deny users="?"/>
   </authorization>
  </system.web>
</location>

#2


0  

Try changing deny element to question mark:

尝试将deny元素更改为问号:

    <authorization>
        <allow roles="Adminstator" />
        <deny users="?" />
    </authorization>

#3


0  

Try spelling Administrator correctly:

尝试正确拼写管理员:

<allow roles="Administrator" />