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 ...
随机推荐
- [LintCode] Pow(x, n) 求x的n次方
Implement pow(x, n). Notice You don't need to care about the precision of your answer, it's acceptab ...
- Defining custom settings in Odoo
Unfortunately Odoo documentation doesn’t seem to include any information about adding new configurat ...
- 细说jQuery原型的创建和实现原理,并用实例简单模仿
在解析jQuery实现机理之前,我们先总结一下几点知识,这些都是我学习路上遇到的坑,我跌倒过很多次,现在把它补上: 1)自定义构造函数,如下例: function person(){ this.nam ...
- thinkphp框架验证码验证一次
做异步验证验证码,只要验证一次结果正确,拿相同的值再次来对比,返回结果就不正确.我看到论坛中有人说,tp框架只要验证过一次正确后验证码就销毁了.确实是这个效果,但具体的还没深入了解
- 使用Fiddler的X5S插件查找XSS漏洞
OWASP top 10的安全威胁中的CrossSite Scripting(跨站脚本攻击),允许攻击者通过浏览器往网站注入恶意脚本.这种漏洞经常出现在web应用中需要用户输入的地方,如果网站有XSS ...
- HTTP协议 (七) Cookie
HTTP协议 (七) Cookie Cookie是HTTP协议中非常重要的东西, 之前拜读了Fish Li 写的[细说Cookie], 让我学到了很多东西.Fish的这篇文章写得太经典了. 所以我这篇 ...
- 使用plupload做一个类似qq邮箱附件上传的效果
公司项目中使用的框架是springmvc+hibernate+spring,目前需要做一个类似qq邮箱附件上传的功能,暂时只是上传小类型的附件 处理过程和解决方案都需要添加附件,处理过程和解决方案都可 ...
- JS开发windows phone8.1系列之1
http://msdn.microsoft.com/zh-cn/library/windows/apps/dn629638.aspx,要点: 1.了解项目结构:package.appxmanifest ...
- Date类型-演示JS中的日期
<script type="text/javascript"> /* *演示JS中的日期 */ var date = new Date(); document.writ ...
- DDoS deflate+iptables防御轻量级ddos攻击
一.查看攻击者ip #netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n 二.安装ddos deflate ...