我是ASP.NET新手,在ASP.NET上開發我的第一個基於web的應用程序。我應該做角色管理。項目中有三種文件夾; 1.ADMIN 2.MEMBER 3.ANOYNOMUS 我想在web.config端設置角色。如何在web.config中執行此操作? 我在網上找不到有用的信息,關於這個主題的數據庫方面? 我應該有一個表,大約是隻有角色嗎?還是我要補充「角色」屬性設置爲管理員和會員表..提前爲您的答覆 謝謝..一般ASP.NET角色管理
1
A
回答
1
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(Partial View)----------------- ----
@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>
相關問題
- 1. asp.net角色管理
- 2. 在ASP.NET網站管理角色管理
- 3. Asp.net MVC角色管理器
- 4. asp.net中的角色管理
- 5. Asp.Net Mvc身份角色管理
- 6. Windows Workflow 4 + ASP.NET角色管理器
- 7. 管理員/客戶角色(ASP.NET)
- 8. ASP.Net成員資格和角色管理
- 9. asp.net角色管理器錯誤
- 10. ASP.NET Active Directory角色 - 管理重疊角色
- 11. Rails:角色/管理
- 12. AspNet.Identity角色管理
- 13. 角色界面和管理角色
- 14. MVC3中的角色管理
- 15. Symfony2 - 動態角色管理
- 16. Azure AD B2C - 角色管理
- 17. 變量角色管理
- 18. Gerrit管理員角色
- 19. Buddypress用戶角色管理
- 20. 設置管理員角色
- 21. Azure角色配置管理
- 22. 用戶在角色「管理員」,但[授權(角色=「管理員」)]將不驗證
- 23. asp.net會員 - 讓管理員用戶在角色方面管理網站
- 24. ASP.NET授權屬性和管理員用戶角色
- 25. 管理不同的用戶角色ASP.NET MVC
- 26. 使用ASP.NET內置控件進行角色管理
- 27. ASP.NET角色管理,這是如何工作的?
- 28. 在ASP.net中的自定義角色和用戶管理MVC 4
- 29. ASP.NET Core Identity:角色管理器沒有服務
- 30. 微小的自定義角色管理asp.net的MVC 3