custom-attributes

UrlHelper and ViewContext inside an Authorization Attribute

I have a scenario that I haven't been able to solve: I'm toying around with creating my own custom authorization attribute for mvc. The main bit of functionality I would like to add is to have the ability to change where the user gets redirected if they are not in a certain role. I don't mind that the system sends them back to the login...

Working with custom role in VB.NET win application

Hi, I am looking for ways to implement custom user-roles in windows application with vb.net. I got a database table called Roles with Administrator and User entries. User cannot see some of the form data. In ASP.NET MVC we can do like. [Authorize(Roles = "Administrator")] public function GetAccount() as Array End Function If it cou...

Can you change a custom attribute from a controller in ASP.NET MVC?

I am looking to have an attribute "show" on certain properties in my class and give the user the option to show other properties in the view. Can I change a custom attribute from the front end? ...

Is it a bad practice to add extra attributes to html elements?

Hi, Sometimes I add an attribute to some of my controls. Like: <a href id="myLlink" isClimber="True">Chris Sharma</a> I know it is not a valid html. But it helps me in some cases. Is this considered as a bad practice? A friend of mine says that it is ok for Intranet environment but on internet it might not be find friendly by search...

Setting the value of textboxes with one of their attributes (jQuery)

I have a bunch of input text boxes that have the attribute ORIGINAL set to their initial value, so that when the user changes the textbox value, jQuery can highlight items that have changed (by comparing the text box's current value to the ORIGINAL attribute's value) What Im trying to do now is provide the user with a button that they c...

Custom fine-grained claims based authorization system in ASP.NET MVC - wheres and hows

So, I'd like to implement my own custom authorization system in MVC2. If I'd have to create a global class, where do I instantiate it? Can HttpContext be extended with my own additions and where do I do that? Should I use Authorization filters for rights validation or ActionFilters or do it within an action? Can ActionFilter pass any da...

ASP MVC C#: Is it possible to pass dynamic values into an attribute?

Okay I'm very new to C# and i'm trying to create a little website using ASP MVC2. I want to create my own authorization attribute. but i need to pass some values if this is possible. For example: [CustomAuthorize(GroupID = Method Parameter?] public ActionResult DoSomething(int GroupID) { return View(""); } I ...

Alternative of custom attrbutes for tags to store some information in HTML 4

Hello All: Can some body tell me any alternative to store some information for a particular tag in HTML 4. For example If I have a drop down like <select> <option value="0" regionId="1">Test1</option> <option value="1" regionId="2">Test2</option> </select> Here regionId is a custom attribute, I am able to access the attribute but the...

Setting an attribute property to the type of the decorated class.

Is it possible to get the decorated class' type inside of the custom attribute's class? For example: [MetadataAttribute] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property, AllowMultiple = false)] public class ViewAttribute : ExportAttribute { public object TargetRegion { get; set; } public Type ViewModel { get;...

Is restricting attributes to class or properties doable?

I have two custom attributes defined like so: internal class SchemaAttribute : Attribute { internal SchemaAttribute(string schema) { Schema = schema; } internal string Schema { get; private set; } } internal class AttributeAttribute : Attribute { internal AttributeAttribute(string attribute) { Attribute...

Magento loadByAttribute for Custom Category Attributes

I have created custom attributes for a category in my module's install script like so: $attrib = array( 'type' => 'varchar', 'group' => 'My Data', 'backend' => '', 'frontend' => '', 'label' => 'My Custom Field', 'input' => 'text', 'class...

J2EE: Default values for custom tag attributes

So according to Sun's J2EE documentation (http://docs.sun.com/app/docs/doc/819-3669/bnani?l=en&amp;a=view), "If a tag attribute is not required, a tag handler should provide a default value." My question is how in the hell do I define a default value as per the documentation's description. Here's the code: <%@ attribute name="visible" ...

Getting all the fields and properties of a custom attribute from a specific instance

I have a custom attribute PackerAttrib which takes no data, simply marking a field or property, which will be used to mark a property or field of a class inherited from Panel in order to serialize it later on. How would I take an instance of any object derived from Panel and get a Directory<string s, object o> where s is the name of the ...

custom attribute changes in .NET 4

I recently upgraded a C# project from .NET 3.5 to .NET 4. I have a method that extracts all MSTest test methods from a given list of MethodBase instances. Its body looks like this: return null == methods || methods.Count() == 0 ? null : from method in methods let testAttribute = Attribute.GetCustomAttribute(method, ...

In C# can I make auto-property perform some extra work with a help of an attribute?

This question is related but not the same as this: http://stackoverflow.com/questions/40730/how-do-you-give-a-c-auto-property-a-default-value I love auto-properties, but sometimes I have to do something like this: private string someName; public string SomeName { get { return someName; } set { someN...

How to replace auto-implemented c# get body at runtime or compile time?

I've been trying to figure this out all night, but I guess my knowledge of the .Net Framework just isn't that deep and the problem doesn't exactly Google well, but if I can get a nod in the right direction I'm sure I can implement it, one way or another. I'd like to be able to declare a property decorated with a custom attribute as such...

What is the usefulness of placing attributes on specific parameters of a method?

I'm looking for a list of reasonable use cases of putting attributes in a parameter. I can think of some good cases for attributes in a method, but can't seem to see a good usage of a parameter attribute. Please, enlighten me. And what about attributes on the return type of a method? ...

How to attach a description to each ActionMethod in a Controller (ASP.net MVC)?

So recently, I came up with a way to dynamically build a nav-bar menu where the Controller (And its Index ActionMethod) would be listed in a horizontal bar at the top of each page (via Site.Master) but also based on the user's assigned roles. Each Controller listed would also list (in a vertical drop-down) the ActionMethods available to ...

ICustomAttributeProvider.GetCustomAttributes(...): Design Strangety?

The MSDN Documentation: MemberInfo.GetCustomAttibutes Method (Type, Boolean) states in the remarks: This method ignores the inherit parameter for properties and events. To search the inheritance chain for attributes on properties and events, use the appropriate overloads of the Attribute.GetCustomAttributes method. This basically m...

ViewStub with custom View attributes for target layout.

Is it possible to pass custom attributes through a ViewStub to the target layout's root element? Like so: <ViewStub android:layout="@layout/custom_view" app:customAttr="12345" /> Where custom_view.xml is: <blah.CustomView ...> ... </blah.CustomView> When I try to do that, CustomView.java does not get "ap...