Click here to Skip to main content
Rate this: bad
good
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.
 
thanks
Posted 5-Sep-12 2:00am
Edited 5-Sep-12 2:27am
v2
Comments
Sandeep Mewara at 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 at 28-Sep-12 16:07pm
   
I don't think this is a valid idea. -- please see my answer and OP's comment below.
--SA
sawant parag at 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 at 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.
--SA

1 solution

Rate this: bad
good
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:
http://msdn.microsoft.com/en-us/library/system.attribute.getcustomattributes.aspx[^].
 
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.
 
—SA
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 85
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 28 Sep 2012
Copyright © CodeProject, 1999-2014
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