Quantcast
Channel: ASP.NET MVC / Web API / Web Pages
Viewing all articles
Browse latest Browse all 7925

Edited Issue: Attribute inheritance preference not being honored by Per-Controller logic [161]

$
0
0
I have a custom controller config attribute created like the following:

[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
public class MyConfigAttribute : Attribute, IControllerConfiguration
{
public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
{
controllerSettings.Formatters.Clear();

controllerSettings.Formatters.Add(new PlainTextFormatter());
}
}

My controllers are like the following:
-----------------------------------------
[MyConfig]
public class BaseApiController : ApiController
{
}

public class BugReproTestsController : BaseApiController
{
public string GetString()
{
return "Hello";
}
}

Request
---------
GET http://kirandesktop:9090/BugReproTests/GetString HTTP/1.1
Accept: application/xml
Host: kirandesktop:9090
Connection: Keep-Alive

Expected Response
---------------------
HTTP/1.1 200 OK
Content-Length: 82
Content-Type: application/xml; charset=utf-8
Server: Microsoft-HTTPAPI/2.0
Date: Thu, 17 May 2012 23:02:35 GMT

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Hello</string>

Actual Response
-------------------
HTTP/1.1 200 OK
Content-Length: 5
Content-Type: text/plain
Server: Microsoft-HTTPAPI/2.0
Date: Thu, 17 May 2012 22:58:21 GMT

Hello


Problem
----------
Even though the MyConfigAttribute says "Inherited=false", the attribute is being applied to the sub-controller.


Viewing all articles
Browse latest Browse all 7925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>