2011-07-23 16 views
1

私はASP.NETで初めてで、ASP.NETで私の最初のWebベースのアプリケーションを開発しています。ロール管理を行うべきです。プロジェクトには3種類のフォルダがあります。 1.ADMIN 2.MEMBER 3.ANOYNOMUS 私はweb.config側でロールを設定したいと思います。どうすればweb.configで実行できますか? このテーマのデータベース側について、私は有用な情報をウェブで見つけることができませんでしたか? は、私は約だけの役割であるテーブルを持っているべきですか?それとも私が管理し、メンバーテーブルへの役割 'プロパティを追加する必要があります..あなたの回答を事前に 感謝..一般的にASP.NETロール管理

答えて

1

Thisチュートリアルシリーズとのthisチュートリアルを特にユーザー役割の作成と管理は、あなたのために役立つはずです。

ASP.NET構成を使用して、さまざまなフォルダのユーザーロールとアクセスルールを構成することもできます。ソリューションエクスプローラ(またはProject \ Website-> ASP.NET Configuration)の右隅にある小さなアイコンで開きます。

ASP.NET構成では、セキュリティ - >アクセスルール - >適切なフォルダのアクセスルールの管理を使用します。

0

----------------------------- AdminRoleController ---------------- --------------

using SamarpanInfotech.Areas.Admin.Controllers; 
using SamarpanInfotech.Core; 
using SamarpanInfotech.DataModel; 
using SamarpanInfotech.Services; 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Web; 
using System.Web.Mvc; 

namespace SamarpanInfotech.Controllers 
{ 
    [RoutePrefix("Admin")] 
    public class AdminRoleController : AdminBaseController 
    { 
     RoleServices roleServices = new RoleServices(); 
     [Route("Role")] 
     public ActionResult Index() 
     { 
      var _list = roleServices.GetRole(1, 20, "RoleName descending", string.Empty); 
      return View(_list); 
     } 
     [Route("Role/Filter")] 
     public PartialViewResult FilterList(int page = 1, int pagerow = 20, string sortby = "RoleName descending", string search = null) 
     { 
      var _list = roleServices.GetRole(page, pagerow, sortby, search); 
      return PartialView("~/Areas/Admin/Views/AdminRole/DisplayTemplates/_List.cshtml", _list); 
     } 
     [Route("Role/Add")] 
     public ActionResult AddRole() 
     { 
      RoleRightListModel model = new RoleRightListModel(); 
      model.RightModel = roleServices.GetRightModel(); 
      return View(model); 
     } 
     [HttpPost] 
     [Route("Role/Add")] 
     public ActionResult AddRolePost(RoleRightListModel model) 
     { 
      roleServices.AddEditRoleRight(model, ProjectSession.AdminUser.Id); 
      this.ShowMessage(MessageExtension.MessageType.Success, "Record successfully saved", true); 
      return RedirectToAction("Index","AdminRole"); 
     } 
     [Route("Role/Edit/{Id}")] 
     public ActionResult EditRole(Guid? Id) 
     { 
      if (Id == null) 
      { 
       return new HttpStatusCodeResult(HttpStatusCode.BadRequest); 
      } 
      var editRoleRight = roleServices.GetRoleRightModel(Id); 
      if (editRoleRight == null) 
      { 
       return HttpNotFound(); 
      } 
      return View(editRoleRight); 
     } 
     [HttpPost] 
     [Route("Role/Edit/{Id}")] 
     public ActionResult EditRolePost(RoleRightListModel model) 
     { 
      roleServices.AddEditRoleRight(model); 
      this.ShowMessage(MessageExtension.MessageType.Success, "Successfully updated", true); 
      return RedirectToAction("Index", "AdminRole"); 
     } 
     [Route("Role/Delete/{Id}")] 
     public ActionResult DeleteRole(Guid Id) 
     { 
      roleServices.Delete(Id); 
      this.ShowMessage(MessageExtension.MessageType.Success, "Successfully deleted", true); 
      return RedirectToAction("Index", "AdminRole"); 
     } 
    } 
} 

----------------------------- ----- Index.cshtml -------------------------------

@model SamarpanInfotech.Core.Paging.PagerList<SamarpanInfotech.DataModel.Role> 
@{ 
    ViewBag.Title = "Index"; 
} 
@section styles{ 
    <link href="~/assets/layouts/layout/css/custom.min.css" rel="stylesheet" /> 
} 
<!-- BEGIN PAGE BAR --> 
<div class="page-bar m-btm-20"> 
    <ul class="page-breadcrumb"> 
     <li> 
      <a href="@Url.Action("Index", "AdminDashboard")">Home</a> 
      <i class="fa fa-circle"></i> 
     </li> 
     <li> 
      <span>Role</span> 
     </li> 
    </ul> 
</div> 
<!-- END PAGE BAR --> 
<form method="post" class="form-horizontal"> 
    @Html.RenderMessages() 
    <div class="row"> 
     <div class="col-md-12"> 
      <div class="table-toolbar"> 
       <div class="row"> 
        <div class="col-md-6 col-sm-6"> 
         <div class="btn-group"> 
          <a class="btn green" href="@Url.Action("AddRole","AdminRole")"> 
           Add Role 
           <i class="fa fa-plus"></i> 
          </a> 
         </div> 
        </div> 
        <div class="col-md-4 col-sm-4 col-md-offset-2"> 
         <div class="input-group"> 
          <input type="text" placeholder="Searching..." name="search" class="form-control input-sm in-sm-h-35 input-inline input-lg input-lg-pd5" id="extendBox"> 
          <span class="input-group-btn"> 
           <button class="btn green in-sm-h-35" type="button" id="btnSearch" action-url="@Url.Action("FilterList", "AdminRole")" target-id="#target-load"> 
            Search 
           </button> 
          </span> 
         </div> 
        </div> 
       </div> 
      </div> 
      <div class="target-load hide-x" id="target-load"> 
       @Html.Partial("~/Areas/Admin/Views/AdminRole/DisplayTemplates/_List.cshtml", Model) 
      </div> 
     </div> 
    </div> 
</form> 
@section scripts 
{ 
    <script> 
     $(document).on('click', ".delete", function (e) { 
      if (confirm("Are you sure want to delete?")) { 
       return true; 
      } 
      e.preventDefault(); 
      return false; 
     }); 
    </script> 
} 

---- --------------------------_ List.cshtml(部分表示)----------------- ----

@model SamarpanInfotech.Core.Paging.PagerList<SamarpanInfotech.DataModel.Role> 
<table class="table table-bordered dataTable" target=".target-load" id="sample_editable_1"> 
    <thead> 
     <tr> 
      @Html.Sorting(Url.Action("FilterList"), "RoleName", "Role Name", Model.SortBy, new { item_page = Model.PageRows }) 
      @Html.Sorting(Url.Action("FilterList"), "AboutRole", "About Role", Model.SortBy, new { item_page = Model.PageRows }) 
      <th>Action</th> 
     </tr> 
    </thead> 
    <tbody> 
     @foreach (var item in Model.PageList) 
     { 
      <tr class="gradeX"> 
       <td>@item.RoleName</td> 
       <td>@item.AboutRole</td> 
       <td> 
        <a href="@Url.Action("EditRole", "AdminRole", new { Id = item.Id })" title="Edit" class="btn btn-outline btn-circle btn-sm purple"> 
         <i class="fa fa-edit"></i> 
        </a> 
        <a href="@Url.Action("DeleteRole", "AdminRole", new { Id = item.Id })" title="Delete" class="btn btn-outline btn-circle btn-sm red delete"> 
         <i class="fa fa-trash-o"></i> 
        </a> 
       </td> 
      </tr> 
     } 

    </tbody> 
</table> 
<div class="row master-pager"> 
    @Html.PagerFrontend(Url.Action("FilterList", "AdminRole"), Model.PageNumber, Model.TotalRows, Model.PageRows, Model.SortBy) 
</div> 

---- ---------------------------- AddRole.cshtml ------------------- ---------

@model SamarpanInfotech.DataModel.RoleRightListModel 
@{ 
    ViewBag.Title = "AddRole"; 
} 
<div class="row"> 
    <div class="col-md-12"> 
     <div class="portlet light portlet-fit portlet-form bordered"> 
      <div class="portlet-title"> 
       <div class="caption"> 
        <span>Create Role</span> 
       </div> 
      </div> 
      @using (Html.BeginForm("AddRolePost", "AdminRole", FormMethod.Post, new { @class = "form-horizontal", role = "form" })) 
      { 
       <div class="portlet-body form"> 
        <div class="form-group"> 
         @Html.LabelFor(m => m.RoleCode, new { @class = "control-label col-md-2" }) 
         <div class="col-md-3"> 
          @Html.TextBoxFor(model => model.RoleCode, new { @class = "form-control", placeholder = "Role Code" }) 
          @Html.ValidationMessageFor(model => model.RoleCode, "", new { @class = "text-danger" }) 
         </div> 
        </div> 
        <div class="form-group"> 
         @Html.LabelFor(m => m.RoleName, new { @class = "control-label col-md-2" }) 
         <div class="col-md-3"> 
          @Html.TextBoxFor(model => model.RoleName, new { @class = "form-control", placeholder = "Role Name" }) 
          @Html.ValidationMessageFor(model => model.RoleName, "", new { @class = "text-danger" }) 
         </div> 
        </div> 
        <div class="form-group"> 
         @Html.LabelFor(m => m.AboutRole, new { @class = "control-label col-md-2" }) 
         <div class="col-md-3"> 
          @Html.TextAreaFor(model => model.AboutRole, new { @class = "form-control", placeholder = "About Role" }) 
          @Html.ValidationMessageFor(model => model.AboutRole, "", new { @class = "text-danger" }) 
         </div> 
        </div> 
       </div> 
       <table class="table table-bordered table-striped dataTable"> 
        <thead> 
         <tr> 
          <th>Rights</th> 
          <th>IsAll ?</th> 
          <th>IsView ?</th> 
          <th>IsAdd ?</th> 
          <th>IsEdit ?</th> 
          <th>IsDelete ?</th> 
         </tr> 
        </thead> 
        <tbody> 
         @{ 
       var count = 0; 
         } 
         @foreach (var item in Model.RightModel) 
         { 
          <tr class="gradeX"> 

           @Html.Hidden("RightModel[" + count + "].RightId", item.RightId, new { @RightId = "RightModel[" + count + "].RightId" }) 
           <td>@item.RightName</td> 
           <td>@Html.RightCheckBox("IsAllVisible", item.IsAllRight, "RightModel[" + count + "]", item.IsAllVisible)</td> 
           <td>@Html.RightCheckBox("IsViewVisible", item.IsViewRight, "RightModel[" + count + "]", item.IsViewVisible)</td> 
           <td>@Html.RightCheckBox("IsAddVisible", item.IsAddRight, "RightModel[" + count + "]", item.IsAddVisible)</td> 
           <td>@Html.RightCheckBox("IsEditVisible", item.IsEditRight, "RightModel[" + count + "]", item.IsEditVisible)</td> 
           <td>@Html.RightCheckBox("IsDeleteVisible", item.IsDeleteRight, "RightModel[" + count + "]", item.IsDeleteVisible)</td> 
          </tr> 
          count = count + 1; 
         } 

        </tbody> 
       </table> 
       <div class="row m-btm-20"> 
        <div class="col-md-offset-2 col-md-9"> 
         <input type="submit" class="btn blue" value="Submit"> 
         <a type="button" class="btn grey-salsa btn-outline" href="@Url.Action("Index","AdminRole")">Cancel</a> 
        </div> 
       </div> 
      } 
     </div> 
    </div> 
</div> 

-------------------------------- EditRole。 cshtml ------------------------------

@model SamarpanInfotech.DataModel.RoleRightListModel 
@{ 
    ViewBag.Title = "EditRole"; 
} 
<div class="row"> 
    <div class="col-md-12"> 
     <div class="portlet light portlet-fit portlet-form bordered"> 
      <div class="portlet-title"> 
        <div class="caption"> 
         <span>Edit Role</span> 
        </div> 
       </div> 
      @using (Html.BeginForm("EditRolePost", "AdminRole", FormMethod.Post, new { @class = "form-horizontal", role = "form" })) 
      { 
       @Html.HiddenFor(model => model.RoleId) 
       <div class="portlet-body form"> 
        <div class="form-group"> 
         @Html.LabelFor(m => m.RoleCode, new { @class = "control-label col-md-2" }) 
         <div class="col-md-3"> 
          @Html.TextBoxFor(model => model.RoleCode, new { @class = "form-control", placeholder = "Role Code" }) 
          @Html.ValidationMessageFor(model => model.RoleCode, "", new { @class = "text-danger" }) 
         </div> 
        </div> 
        <div class="form-group"> 
         @Html.LabelFor(m => m.RoleName, new { @class = "control-label col-md-2" }) 
         <div class="col-md-3"> 
          @Html.TextBoxFor(model => model.RoleName, new { @class = "form-control", placeholder = "Role Name" }) 
          @Html.ValidationMessageFor(model => model.RoleName, "", new { @class = "text-danger" }) 
         </div> 
        </div> 
        <div class="form-group"> 
         @Html.LabelFor(m => m.AboutRole, new { @class = "control-label col-md-2" }) 
         <div class="col-md-3"> 
          @Html.TextAreaFor(model => model.AboutRole, new { @class = "form-control", placeholder = "About Role" }) 
          @Html.ValidationMessageFor(model => model.AboutRole, "", new { @class = "text-danger" }) 
         </div> 
        </div> 
       </div> 
       <table class="table table-bordered table-striped dataTable"> 
        <thead> 
         <tr> 
          <th>Rights</th> 
          <th>IsAll ?</th> 
          <th>IsView ?</th> 
          <th>IsAdd ?</th> 
          <th>IsEdit ?</th> 
          <th>IsDelete ?</th> 
         </tr> 
        </thead> 
        <tbody> 
         @{ 
          var count = 0; 
         } 
         @foreach (var item in Model.RightModel) 
         { 
          <tr class="gradeX"> 
           @Html.Hidden("RightModel[" + count + "].RightId", item.RightId, new { @RightId = "RightModel[" + count + "].RightId" }) 
           <td>@item.RightName</td> 
           <td>@Html.RightCheckBox("IsAllVisible", item.IsAllRight, "RightModel[" + count + "]", item.IsAllVisible)</td> 
           <td>@Html.RightCheckBox("IsViewVisible", item.IsViewRight, "RightModel[" + count + "]", item.IsViewVisible)</td> 
           <td>@Html.RightCheckBox("IsAddVisible", item.IsAddRight, "RightModel[" + count + "]", item.IsAddVisible)</td> 
           <td>@Html.RightCheckBox("IsEditVisible", item.IsEditRight, "RightModel[" + count + "]", item.IsEditVisible)</td> 
           <td>@Html.RightCheckBox("IsDeleteVisible", item.IsDeleteRight, "RightModel[" + count + "]", item.IsDeleteVisible)</td> 
          </tr> 
          count = count + 1; 
         } 

        </tbody> 
       </table> 
       <div class="row m-btm-20"> 
        <div class="col-md-offset-2 col-md-9"> 
         <input type="submit" class="btn blue" value="Submit"> 
         <a type="button" class="btn grey-salsa btn-outline" href="@Url.Action("Index","AdminRole")">Cancel</a> 
        </div> 
       </div> 
      } 
     </div> 
    </div> 
</div> 
<script> 
    $(document).ready(function() { 
     $(document).on("change", "#IsAllVisible", function (e) { 
      var CheckIsAll = $('#IsAllVisible').val(); 
      if (CheckIsAll == true) 
      { 
       $('#IsViewVisible').val() == true; 
       $('#IsAddVisible').val() == true; 
       $('#IsEditVisible').val() == true; 
       $('#IsDeleteVisible').val() == true; 
      } 
     }) 
    }); 
</script> 
関連する問題