Create and Use Custom Attributes
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的更多相关文章
- THREE.js代码备份——webgl - custom attributes [lines](自定义字体显示、控制字图的各个属性)
<!DOCTYPE html> <html lang="en"> <head> <title>three.js webgl - cu ...
- 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 ...
- [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 ...
- Android Attr -- Understanding Android Custom Attributes
原文:http://androidbook.com/item/4169
- Boto3
https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.htmlboto3 安装pip install bot ...
- [转]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 ...
- How to: Create Custom Configuration Sections Using ConfigurationSection
https://msdn.microsoft.com/en-us/library/2tw134k3.aspx You can extend ASP.NET configuration settings ...
- 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 ...
- 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 ...
随机推荐
- tomcat域名问题
首先可以确认,tomcat支持以下的配置: 1.同一个tomcat配置多个端口来发布不同的应用,配置多个<Service>即可; 2.同一个tomcat可以配置多个虚拟主机,以指定不同的域 ...
- Spring注解详解
概述 注释配置相对于 XML 配置具有很多的优势: 它可以充分利用 Java 的反射机制获取类结构信息,这些信息可以有效减少配置的工作.如使用 JPA 注释配置 ORM 映射时,我们就不需要指定 PO ...
- NLP文本情感分类传统模型+深度学习(demo)
文本情感分类: 文本情感分类(一):传统模型 摘自:http://spaces.ac.cn/index.php/archives/3360/ 测试句子:工信处女干事每月经过下属科室都要亲口交代24口交 ...
- 中介者模式(Mediator)
GOF:用一个中介对象来封装一系列的对象交互.中介者使对象不需要显式地相互引用,从而使其耦合松散,而且可以独立地改变它们之间的交互. 类图:
- java之接口(笔记)
1.特征 (1)所有成员变量都是public, static, final.(2)所有方法都是public, abstract.(3)所有嵌套类型都是public, static. 2.接口也是继承自 ...
- EmguCV 轮廓
一.相关函数 public static void cvDrawContours( IntPtr img, IntPtr contour, MCvScalar externalColor, MCvSc ...
- 【iCore3 双核心板】例程三十二:UART_IAP_ARM实验——更新升级STM32
实验指导书及代码包下载: http://pan.baidu.com/s/1hrnLJwC iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...
- dedecms 使用
初看dedecms的后台界面就是一头雾水.不懂的词语多,什么模型,什么栏目,什么频道,不懂.相比于wordpress的分类category,标签tag,文章post,页面page而言,织梦后台难懂. ...
- centos安装配置amoeba以及测试
一.amoeba介绍网址:http://docs.hexnova.com/amoeba/ 二.安装java se1.5 三.安装amoeba2.2.01.下载地址:http://sourceforge ...
- Wb应用程序开放原理
简介:基于wb的浏览器/服务器(简称B/S),架构编程,已经成为目前企业级应用程序开发的主流. 1.企业应用计算的演变:主机/呀终端的集中 ...