This repository was archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
FromHeaderAttribute with Name doesn't work on class properties #1929
Copy link
Copy link
Closed
Description
When specifying the name property on a `[FromHeader(Name = "User-Agent)]" the binding doesn't occur.
Repro
Application code:
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc;
using Microsoft.Framework.DependencyInjection;
namespace Repro
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app)
{
app.UseMvc();
}
}
public class HomeController : Controller
{
[HttpGet("[controller]/[action]/{RouteValue?}")]
public IActionResult TestBind(Values v, [FromHeader(Name = "User-Agent")]string header)
{
string message = "Header value: " + v.UserAgent +
"\nHeader parameter: " + header +
"\nRoute Value: " + v.RouteValue +
"\nQuery Value: " + v.QueryValue;
return Content(message);
}
}
public class Values
{
[FromHeader(Name = "User-Agent")]
public string UserAgent { get; set; }
[FromRoute]
public string RouteValue { get; set; }
[FromQuery]
public string QueryValue { get; set; }
}
}
project.json
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000",
},
"frameworks": {
"aspnet50": { }
}
}
Url
http://localhost:5000/Home/TestBind/asd?QueryValue=4
Expected (with Chrome)
Header value: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36
Header parameter: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36
Route Value: asd
Query Value: 4
Actual (with Chrome)
Header value:
Header parameter: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36
Route Value: asd
Query Value: 4