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 ...
随机推荐
- 使用explain查看mysql查询执行计划
explain语句: 字段解释: type: all(全表扫描) ref() possible_keys: 预测使用什么列做为索引 key: 实际使用的key ...
- Javascript 编程小技巧总结(部分内容借鉴他人)
1 – 使用===,而不是== ==(或!=)操作符在需要的时候会自动执行类型转换.===(或!==)操作不会执行任何转换.它将比较值和类型,而且在速度上也被认为优于==. 2 – 使用闭包实现私有变 ...
- 导出查询结果到excle
实现功能 输入查询结果 点击导出查询结果 导出到excle表.
- xml、文件操作功能类
我一个项目中用到的,里面的方法不是太通用,但是可以从里面找到一些有用的代码,以后慢慢添补更新: FileUtil.xml package com.novel.util; import java.io. ...
- java final方法的作用
1. 不想让别人修改方法实现. 2. 在方法调用时使用内嵌调用. 3. 有效的“关闭”动态绑定,这样编译器就可以为final方法调用生成更有效的代码. Java编程思想: “然而,大多数情况下,这样做 ...
- Android课程---环境配置很重要
- 用Scala实现集合中相邻元素间的差值
欢迎转载,转载请注明出处,徽沪一郎. 概要 代码这东西,不写肯定不行,新学Scala不久,将实际遇到的一些问题记录下来,日后也好查找. 今天讲的是如何计算同一集合中元素两两之间的差值,即求开始集合(a ...
- java实现文件及目录压缩
package org.alfresco.repo.bom.util; import java.io.File; import java.io.FileInputStream; import java ...
- Bootstrap《第一篇》,关于container、jumbotron、row、col、text-center等的学习
一.关于引入bootstrap文件 <!-- 为了确保适当的绘制和触屏缩放,需要在 <head> 之中添加 viewport 元数据标签. --> <meta name= ...
- 欢快的使用Unity JSON吧
0x01:前言 Unity 5.3加入了UnityUtility类,意味着Unity终于有了自己原生态的JSON库.Unity主要用来游戏开发,JSON做为游戏开发中最受欢迎的配置文件.在官方没有库支 ...