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

最新文章

  1. C#实现二维码功能,winform 以及 asp.net均可以用
  2. duilib的caption上的Edit无法激活
  3. linux常用命令之文件系统
  4. mysql学习笔记 第八天
  5. spring mvc中的valid
  6. 解决ASP.NET使用IIS架设网站时“服务器应用程序不可用”的方法
  7. [Objective-c 基础 - 2.5] .h和.m文件,点语法,成员变量作用域
  8. mysql主从监控
  9. poj 3308 (最大流)
  10. Windows 下统计行数的命令
  11. 【QT相关】Qt Widgets Module
  12. SystemTap----将SystemTap脚本编译成内核模块
  13. Python中闭包、装饰器的概念
  14. Ubuntu与Centos在登陆安全方面的比较
  15. [Swift]LeetCode46. 全排列 | Permutations
  16. scala查询dataFrame结构
  17. python 进程/线程/协程 测试
  18. centos7搭建ELK Cluster集群日志分析平台(二):Logstash
  19. python网络爬虫笔记(四)
  20. 【转】PHP 杂谈 坑爹的file_exists

热门文章

  1. Struts 2入门案例及登录
  2. jQuery获取cookie
  3. php随笔(一)
  4. tab1
  5. getPos封装
  6. HDU 5762
  7. asp.net 获取当前项目的根目录路径
  8. ss命令
  9. php对二维数组进行相关操作(排序、转换、去空白等)
  10. 【Composer】实战操作二:自己创建composer包并提交