asp 4.5基于角色的授权在打开admin文件夹页面后没有加载任何其他页面

时间:2017-07-23 16:20:48

标签: asp.net authentication authorization role

我已经创建了一个asp.net 4.5 Web表单应用程序,并通过以下this文章在其中实现了基于角色的身份验证和授权。虽然我没有使用<asp:Menu/>控件,但我跳过创建web.sitemap文件。我在bootstrap navigational bar页面中使用了site.master

我的应用程序中有三个角色,包括Admin角色。我有一个单独的admin页面,所以我将web form文件移到了Admin文件夹中。以下是我的解决方案的屏幕截图:Project Solution

**我的另外两个角色,接待员和医师在登录后工作正常。他们可以浏览允许的页面。当管理员登录并转到AddPhysician.aspx页面时,url看起来像这样:http://localhost:58246/Admin/AddPhysician.aspx并且加载正常,但nav bar除外(徽标未加载){ {3}}。

现在,当我点击navigational bar(例如Home page)中的任何其他网页时,url如下所示:http://localhost:58246/Admin/Home.aspx。这会给我一个/错误:enter image description here 为什么它在Home.aspx文件夹而不是主目录中搜索Admin页面?**

这是我的根web.config文件:

    <system.web>
  <authentication mode="Forms">
    <forms defaultUrl="~/Home.aspx" loginUrl="~/Login.aspx" slidingExpiration="true" timeout="2880"></forms>
  </authentication>
  <authorization>
    <deny users="?" />
  </authorization>
  </system.web>

以下是web.config文件夹中的内容Admin文件。

  <?xml version="1.0"?>
  <configuration>
  <system.web>
      <authorization>
         <allow roles="Administrator"/>
         <deny users="*"/>
      </authorization>
     </system.web>
 </configuration>

请告诉我是否有人需要其他材料来理解问题。

修改 我在这里添加内容AddPhysician.aspx文件:

    <%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="AddPhysician.aspx.cs" Inherits="PresentationLayer.Admin.AddPhysician" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        body {
            background: inherit;
            margin-top:5%; /*This*/
        }

        table {
            width:50%;
        }

            table.center {
                margin: 0 auto;
                border: 3px solid #bdc3c7;
                border-width: thick;
                border-collapse: separate;
                border-spacing: 1.4em;
                /*background: rgba(211,76,190,0.88);*/
                margin-bottom:5%; /*This*/
                background-image: url(/content/images/physician_tools.jpg);
            }

        .pageTitle {
            font-family: 'Source Sans Pro', sans-serif;
            font-style: oblique;
            text-align: center;
            color:#2c3e50;
            font-weight:700;
        }
        .formLabels{
            color: #3498db;

        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <%--<form  method="post" runat="server">--%>
        <table class="center">
             <tr>
                <td class="">
                    <asp:Label CssClass="label label-info" ID="lblPatientID" Text="User ID" runat="server" /></td>
                <td>
                    <asp:TextBox ID="txtUserID" runat="server" CssClass="form-control input-lg" Enabled="false" ForeColor="#00CC99"/>
                </td>
            </tr>
            <tr >
                <td class="">
                    <asp:Label class="label label-info" ID="lblFristN" Text="First Name" runat="server" /></td>
                <td>
                    <asp:TextBox ID="txtFristN" runat="server" Class="form-control input-sm"/>
                </td>
                <td>
                    <asp:RequiredFieldValidator ID="reqFieldValidatorFName" runat="server" ControlToValidate="txtFristN" Display="None" ErrorMessage="Please Enter First Name"></asp:RequiredFieldValidator>

                </td>
                <td>
                    <asp:RegularExpressionValidator ID="regExpressionValidatorFName" runat="server" ControlToValidate="txtFristN" Display="None" ErrorMessage="Only Lower and Upper case alphabets are allowed in First Name" ValidationExpression="[a-z,A-Z]*"></asp:RegularExpressionValidator>
                </td>
            </tr>
            <tr>
                <td class="">
                    <asp:Label class="label label-info" ID="lblLastN"  Text="Last Name" runat="server" /></td>
                <td>
                    <asp:TextBox Class="form-control input-sm" ID="txtLastN" runat="server" /></td>
                <td>
                    <asp:RequiredFieldValidator ID="reqFieldValidatorLastN" runat="server" ControlToValidate="txtLastN" Display="None" ErrorMessage="Enter the Last Name"></asp:RequiredFieldValidator>

                </td>
                <td>
                    <asp:RegularExpressionValidator ID="regExpressionValidatorLastN" runat="server" ControlToValidate="txtLastN" Display="None" ErrorMessage="Only Lower and Upper case alphabets are allowed in Last Name" ValidationExpression="[a-z,A-Z]*"></asp:RegularExpressionValidator>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblGender" runat="server" Text="Gender" AssociatedControlID="rblGender"></asp:Label>
                </td>
                <td>
                    <asp:RadioButtonList ID="rblGender" runat="server">
                        <asp:ListItem Text="Male" Value="M" />
                        <asp:ListItem Text="Female" Value="F" />
                    </asp:RadioButtonList>
                </td>
                <td>
                    <asp:RequiredFieldValidator ErrorMessage="Please select a gender" ControlToValidate="rblGender" runat="server" />
                </td>
            </tr>
            <tr>
                <td class="">
                    <asp:Label class="label label-info" ID="labelDepartment" Text="Department" runat="server" />
                </td>
                <td>
                    <asp:DropDownList CssClass="form-control input-sm" ID="DropDownLDepartment" runat="server">
                    </asp:DropDownList>
                </td>
                <td>
                    <asp:RequiredFieldValidator ID="reqFieldValidatorDeparment" runat="server" Display="None" ControlToValidate="DropDownLDepartment" InitialValue="Select a Plan" ErrorMessage="Please select an Insurence Plan" />
                </td>
            </tr>
            <tr>
                <td class="">
                    <asp:Label class="label label-info" ID="LabelEduQ"  Text="Educational Qualification" runat="server" /></td>
                <td>
                    <asp:TextBox Class="form-control input-sm" ID="TextBoxEduQ" runat="server" /></td>
                <td>
                    <asp:RequiredFieldValidator ID="ReqFieldValidatorEduQ" runat="server" ControlToValidate="TextBoxEduQ" Display="None" ErrorMessage="Please Enter Educational Qualification"></asp:RequiredFieldValidator>

                </td>
                <td>
                    <asp:RegularExpressionValidator ID="RegExpressionValidatorEduQ" runat="server" ControlToValidate="TextBoxEduQ" Display="None" ErrorMessage="Only Lower and Upper case alphabets and '.'`s and space's are allowed in Educational Qualification" ValidationExpression="[a-zA-Z\s\.]*"></asp:RegularExpressionValidator>
                </td>
            </tr>
            <tr>
                <td class="">
                    <asp:Label class="label label-info" ID="LabelExp"  Text="Years of Experience" runat="server" /></td>
                <td>
                    <asp:TextBox Class="form-control input-sm" ID="TextBoxExp" runat="server" /></td>
                <td>
                    <asp:RequiredFieldValidator ID="ReqFieldValidatorExp" runat="server" ControlToValidate="TextBoxExp" Display="None" ErrorMessage="Please Enter Years of experience"></asp:RequiredFieldValidator>
                </td>
                <td>
                    <asp:RegularExpressionValidator ID="RegExpressionValidatorExp" runat="server" ControlToValidate="TextBoxExp" Display="None" ErrorMessage="Only a one or two digit integer is allowed in Years of Experience" ValidationExpression="[0-9]{1,2}"></asp:RegularExpressionValidator>
                </td>
            </tr>
            <tr>
            <td class="">
                    <asp:Label class="label label-info" ID="LabelState" Text="State" runat="server" />
                </td>
                <td>
                    <asp:DropDownList CssClass="form-control input-sm" ID="DropDownLState" runat="server">
                    </asp:DropDownList>
                </td>
                <td>
                    <asp:RequiredFieldValidator ID="reqFieldValidatorState" runat="server" Display="None" ControlToValidate="DropDownLState" InitialValue="Select a State" ErrorMessage="Please select a state" />
                </td>
            </tr>
            <tr>
                <td class="">
                    <asp:Label class="label label-info" ID="LabelIns" Text="Insurence Plan" runat="server" />
                </td>
                <td>
                    <asp:DropDownList CssClass="form-control input-sm" ID="DropDownLPlns" runat="server">
                    </asp:DropDownList>
                </td>
                <td>
                    <asp:RequiredFieldValidator ID="ReqFieldValidatorIns" runat="server" Display="None" ControlToValidate="DropDownLPlns" InitialValue="Select a Plan" ErrorMessage="Please select an Insurence Plan" />
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <asp:Button  class="btn btn-primary btn-sm" ID="buttonRegister" Text="Register" runat="server" OnClick="btnRegister_Click" CausesValidation="true" />
                </td>
                <td>
                    <asp:Button class="btn btn-primary btn-sm" ID="buttonReset" Text="Reset" runat="server" OnClientClick="" OnClick="btnReset_Click" CausesValidation="false" />
                </td>
            </tr>
            <tr>
                <td>
                    <asp:ValidationSummary ID="ValSumRegister" runat="server" ShowMessageBox="true" ShowSummary="false" />
                </td>
            </tr>
        </table>
    <%--</form>--%>
</asp:Content>

1 个答案:

答案 0 :(得分:0)

不知道这是否是合适的解决方案,但现在就是这样。我只是将AddPhysician.aspx文件移动到主目录并将其inherits目录更改为PresentationLayer.AddPhysician(向后移动目录一次)。然后,我在主location文件中为AddPhysician添加了另一个web.config路径,并将allowed role设置为Administrator并删除了Admin文件夹。现在它工作得很好。

我认为问题是AddPhysician.aspx文件无法正确获取site.master页面。