zoukankan      html  css  js  c++  java
  • 扩展ASP.NET MEMBERSHIP权限功能(四 )之页面权限

      之前介绍的是如何让按钮显示在不同的用户组中,现在需要做的是 如果这本是B组具有新增功能权限访问的页,A组进来后怎么进行提示

      1. HttpModule.cs

      

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web;
    using System.Web.Security;

    namespace EC.Permissions
    {
        
    public class HttpModule : IHttpModule
        {

            
    #region IHttpModule Members

            
    public void Dispose()
            {
                
            }

            
    public void Init(HttpApplication context)
            {
                context.AcquireRequestState 
    += new EventHandler(context_AcquireRequestState);  
            }

            
    void context_AcquireRequestState(object sender, EventArgs e)
            {
                
    if(HttpContext.Current.User!=null)
                
    //检查用户是否登录,并判断是否有页面权限
                if (HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    
    //检查当前页面是否在配置文件中
                    if (!DAL.CheckPage())
                    {
                        
    //可以在这里进行扩展
                        HttpContext.Current.Response.Write("无权限访问此页");
                    }

                }
            }


            
    #endregion
        }
    }

     

      2.打开Webroot 中的web.config

      增加<add name="HttpModule" type="EC.Permissions.HttpModule"/>

      

      3. 新建print.aspx在 Admin/Test/Print.aspx

      访问提示 无权限访问此页

      在Admin/Test/web.config增加

      <Item>
            <Page>Print.aspx</Page>
            <Function>打印</Function>
            <Val>64</Val>
          </Item>

      同时新增SQL

      INSERT INTO aspnet_Ex_PermissionsForRoles
                          (RoleId, ModulePath, PermissionValue) Values
                          ('Your RoleId', '/Admin/Test/print.aspx', 64)

      

      Print.aspx页面代码

      

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Print.aspx.cs" Inherits="Admin_Test_Print" %>
    <%@ Register assembly="EC.Permissions" namespace="EC.Permissions.WebControls" tagprefix="cc1" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        
    <title>hubj.cnblogs.com</title>
    </head>
    <body>
        
    <form id="form1" runat="server">
        
    <div>
        这里是Print.aspx
         
    <cc1:PermissionsButton ID="PermissionsButton1" runat="server" >
                
    <cc1:ButtonItem Text="打印"  Type="PRINT"/>
                
    <cc1:ButtonItem Text="返回" Type="LIST" />
            
    </cc1:PermissionsButton>
        
    </div>
        
    </form>
    </body>
    </html>

      预览显示

      

      细心的朋友会发现为什么返回没有显示出来? 将SQL UPDATE成 66就行了 (Print+List)

      如后台如何管理权限的界面就不在描述,用心的朋友可以试着UPDATE INSERT DELETE 表:aspnet_Ex_PermissionsForRoles

      从下午4点整理到现在,总算写完了,欢迎交流

      完 :)

     

      目录

      扩展ASP.NET MEMBERSHIP权限功能(四 )之页面权限
      扩展ASP.NET MEMBERSHIP权限功能(三 )之权限控件
      扩展ASP.NET MEMBERSHIP权限功能(二 )
      扩展ASP.NET MEMBERSHIP权限功能(一 )

  • 相关阅读:
    627. whose 和 who's
    628. why 和why not
    629 will: 各种用法tyg
    enChapter 3 Underlying Technologiesp
    使用VIEWER.JS进行简单的图片预览
    outlook2010设置失败后重新设置
    新增和编辑clob字段
    金钱大写
    pivot 与 unpivot 函数是SQL05新提供的2个函数
    从函数到委托
  • 原文地址:https://www.cnblogs.com/hubj/p/1735814.html
Copyright © 2011-2022 走看看