Click here to Skip to main content
11,932,734 members (55,683 online)
Rate this:
Please Sign up or sign in to vote.
See more: MVC
wanted to create custom attribute in MVC 3 . and also want to know how to invoke the attribute from controllers. help me to do this.

Posted 5-Sep-12 2:00am
Edited 5-Sep-12 2:27am
Sandeep Mewara 5-Sep-12 7:28am
What kind of help you are seekin/ What have you tried so far? Where are you stuck?
Sergey Alexandrovich Kryukov 28-Sep-12 16:07pm
I don't think this is a valid idea. -- please see my answer and OP's comment below.
sawant parag 18-Sep-12 7:52am
in my application , i am trying to trace the end of session.

Currently when my session end , my javascript menu get disappears .

so i was planing to have some custom attributes that will run on every click on View and check whether session present or not ?
if the session expire then i will redirect that to new custom error page.
Sergey Alexandrovich Kryukov 28-Sep-12 16:07pm
You have no idea what an attribute is. I don't think they will help you in this case. Please see my answer.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

The question is not really related to MVC. You don't "invoke" an attribute — there is no suck think. The attributes are "attributed" the the assemblies, modules, types, members and parameters as additional meta-data. When you execute any portion of your run time, they are already there. All you can do it to examine if the declarations of the programming entities mentioned above have some type of attributes; and if an attribute of certain type is found, you can read its properties. This can be done using some methods named GetCustomAttributes:[^].

There are more methods, but I don't want to show them as they comes with most Reflection types: Assembly, Type, MethodInfo, ConstructorInfo, MemberInfo, FieldInfo, PropertyInfo, ParameterInfo and the like. You would be better off finding appropriate attribute-related methods by yourself, as you need them.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | Last Updated 28 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100