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. silverlight Canvas、StackPanel、Grid三者之间的关系

    学习 silverlight   首先Canvas.StackPanel.Grid 博客园里看到jailu的这篇文章整理得很好 贴下来: Silverlight提供了非常灵活的布局管理系统,让程序员和 ...

  2. UniversalAndroidImageLoader出现异常:ImageLoader: Unable to resolve host "https": No address associated with host

    问题描述 使用ImageLoader时,出现如下错误,始终加载图片错误,显示img_error的图片.UniversalAndroidImageLoader出现异常:ImageLoader: Unab ...

  3. traits的使用

    trait的作用是可以在任何地方使用trait中的方法. trait的定义与定义类相同,定义实例如下: trait tSoneTrait{ //定义一些属性 function someFunction ...

  4. CSS3 Animation

    animation:[<animation-name> || <animation-duration> || <animation-timing-function> ...

  5. toLowerCase和toLocaleLowerCase的区别

    ECMAScript中涉及字符串大小写转换的方法有4个:toLowerCase().toLocaleLowerCase().toUpperCase()和toLocaleUpperCase().其中,t ...

  6. maven pom文件结构详解

    POM文件结构 Project Object Model是Maven2项目的基础所在,简单来说它就是一个XML文件,Maven2用它来描述一个工程的整个生命周期所需要执行的一系列功能和特性. 最小配置 ...

  7. CentOS 安装

    选择选择启动介质 Install or upgrade an existing system: 安装或升级现有的系统 install system with basic video driver: 安 ...

  8. android之消息机制(二)

    消息通道:Looper 首先编写main.xml文件 代码如下: <LinearLayout xmlns:android="http://schemas.android.com/apk ...

  9. 温故而知新,jquery选择器$=

    $("select[name$=Sort]") 可以选择到如下元素: <select class="sort-selec" name="eton ...

  10. U3D--常用属性(不完整,待加)

    1. AddComponentMenu 描述:这个属性可以在Component这个菜单栏下加自己定义的子菜单,这样可以快速添加常用的脚本.该属性要用在类上. using UnityEngine; us ...