http://www.codeproject.com/Articles/1811/Creating-and-Using-Attributes-in-your-NET-applicat

Create a custom attribute class:

[AttributeUsage(AttributeTargets.Class)] // this attribute can only be used by class

public class RequirePermissionAttribute : Attribute
    {
        public string Module { get; set; }

        public string Function { get; set; }

        public RequirePermissionAttribute(string moduleId, string function)
        {
            if(string.IsNullOrEmpty(moduleId))
                throw new ArgumentException("'Module' cannot be empty.", "Module");

            this.Module = moduleId;
            this.Function = function;
        }
    }

Using in class:

[RequirePermission(")]
    public partial class WebForm2 : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }

How to use in BasePage.cs

RequirePermissionAttribute[] attributes = (RequirePermissionAttribute[])Page.GetType().GetCustomAttributes(typeof(RequirePermissionAttribute), true);
                    )
                    {
                        Response.Redirect(ResolveUrl("~/Error.html"));
                    }
                    else
                    {
                        RequirePermissionAttribute attribute = attributes[];
                        string moduleId = attribute.Module;
                        string function = attribute.Function;
                        //validate if has permission by module id and function
                    }

request.UrlReferrer

INPUT

Response.Write("<br/> " + HttpContext.Current.Request.Url.Host);
Response.Write("<br/> " + HttpContext.Current.Request.Url.Authority);
Response.Write("<br/> " + HttpContext.Current.Request.Url.AbsolutePath);
Response.Write("<br/> " + HttpContext.Current.Request.ApplicationPath);
Response.Write("<br/> " + HttpContext.Current.Request.Url.AbsoluteUri);
Response.Write("<br/> " + HttpContext.Current.Request.Url.PathAndQuery);

OUTPUT

localhost
localhost:60527
/WebSite1test/Default2.aspx
/WebSite1test
http://localhost:60527/WebSite1test/Default2.aspx?QueryString1=1&QuerrString2=2
/WebSite1test/Default2.aspx?QueryString1=1&QuerrString2=2

Create and Use Custom Attributes的更多相关文章

  1. THREE.js代码备份——webgl - custom attributes [lines](自定义字体显示、控制字图的各个属性)

    <!DOCTYPE html> <html lang="en"> <head> <title>three.js webgl - cu ...

  2. How to create your own custom 404 error page and handle redirect in SharePoint 分类: Sharepoint 2015-07-08 00:22 4人阅读 评论(0) 收藏

    1. In your MOSS server, make a copy of %systemdrive%\Program Files\Common Files\Microsoft Shared\Web ...

  3. [Cypress] Create a Single Custom Cypress Command from Multiple Commands

    Cypress provides a straightforward API that allows you to define custom commands. In this lesson, we ...

  4. Android Attr -- Understanding Android Custom Attributes

    原文:http://androidbook.com/item/4169

  5. Boto3

    https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.htmlboto3 安装pip install bot ...

  6. [转]How do you create a custom AuthorizeAttribute in ASP.NET Core?

    问: I'm trying to make a custom authorization attribute in ASP.NET Core. In previous versions it was ...

  7. How to: Create Custom Configuration Sections Using ConfigurationSection

    https://msdn.microsoft.com/en-us/library/2tw134k3.aspx You can extend ASP.NET configuration settings ...

  8. How to: Create a C/C++ Union by Using Attributes (C#)

    [How to: Create a C/C++ Union by Using Attributes (C#)] 1.you can create what is known as a union in ...

  9. How to Create a Perl Based Custom Monitor on NetScaler

    How to Create a Perl Based Custom Monitor on NetScaler https://support.citrix.com/article/CTX227727 ...

随机推荐

  1. html5.js让IE(包括IE6)支持HTML5元素方法

    引用Google的html5.js文件 <!--[if IE]> <script src=”http://html5shiv.googlecode.com/svn/trunk/htm ...

  2. unity3d插件Daikon Forge GUI 中文教程3-基础控件Button和Sprite的使用

    2.2添加一个按钮Button 来看看特有的属性:Button Properties Data 显示的文本 Behavior 中的几个: Aoto Size 选中时就是按钮的背景会根据Data中的文本 ...

  3. c#面向对象基础 类、方法、方法重载

    C#是纯粹的面向对象编程语言,它真正体现了“一切皆为对象”的精神.在C#中,即使是最基本的数据类型,如int,double,bool类型,都属于System.Object(Object为所有类型的基类 ...

  4. 注入语句详解(get注入,cookie注入,搜索型注入等)

    注意:对于普通的get注入,如果是字符型,前加'   后加 and ''=' 拆半法 ###################################### and exists (select ...

  5. 【HDU4632 Palindrome subsequence】区间dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4632 题意:给你一个序列,问你该序列中有多少个回文串子序列,可以不连续. 思路:dp[i][j]表示序 ...

  6. ZedBoard 引脚约束参考

    从ISE转换到Vivado时,UCF转XDC的几种方法: (1)软件自动转换 参考网址:Youtube 用ISE->EDK->PlanAhead打开所需转换的工程文件*.xise,并打开b ...

  7. sublime3+quick智能提示

    sublime3+quick智能提示 1. 安装PackegeControl 下载 https://sublime.wbond.net/Package%20Control.sublime-packag ...

  8. mac下使用glew库,方法

    mac下使用glew库,方法 分类: OpenGL2015-01-15 15:52 210人阅读 评论(0) 收藏 举报   目录(?)[+]   主要参考http://www.cnblogs.com ...

  9. BizTalk动手实验(五)Map开发测试

    1 课程简介 通过本课程熟悉Map的相关开发与测试技术 2 准备工作 熟悉XML.XML Schema.XSLT等相关XML开发技术 新建BizTalk空项目 演示 3.1 基本操作 打开MapDev ...

  10. 安装Arch Linux(桌面环境)

    安装xorg-server # pacman -S xorg-server xorg-server-utils xorg-xinit 安装显卡驱动 如果不知道是什么显卡,就使用以下命令查看 # lsp ...