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 ...
随机推荐
- text-indent:-9999px 字体隐藏问题
为什么要字体隐藏? 通常为了传达更好的视觉效果,我们常用图片替代掉字体.但是为了html语义化,常常要给内容模块加上一些标题来让页面更有意义,在抛开css裸奔的情况下也能很顺利的汲取到页面信息.为此我 ...
- 用JAVA写一个日历计划
效果图(自己需要在前台加css修饰)
- ACM Steps 2.1.4
Largest prime factor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- 由easyui的tab在ie下渲染失败,发现的一个有意义的问题
今天项目组的同事反映,在IE浏览器下,所有用easyui编写的tab控件都加载不出来,只会显示一个Loading的提示在控件的内容显示区. 刚分析这个问题,首先怀疑是使用easyui的tab的脚本写法 ...
- Android SDK 镜像站
Android SDK镜像的介绍使用 http://www.androiddevtools.cn 镜像站地址 由于一些原因,Google相关很多服务都无法访问,所以在很多时候我们SDK也无法升级 ...
- Silverlight控件——如何提升应用程序信任度与问题解决
从silverlight5开始,可以在项目设置中勾选“在浏览器内运行时需要提升的信任”来达到在浏览器内运行提权silverlight客户端的目的,在个特性很有用处. 可我使用这个功能时遇到了一个奇怪的 ...
- Java语法基础思维图
- NFS服务器搭建
1. 安装nfs-kernel-server,然后编辑/etc/exports. /sambadata/nfsserver 10.0.0.0/255.255.255.0(fsid=0,all_s ...
- Yii源码阅读笔记(二十六)
Application 类中设置路径的方法和调用ServiceLocator(服务定位器)加载运行时的组件的方法注释: /** * Handles the specified request. * 处 ...
- 读过的laravel文章
Laravel 中使用 JWT(Json Web Token) 实现基于API的用户认证 http://www.tuicool.com/articles/IRJnaa api token https: ...