Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all 7215 articles
Browse latest View live

Commented Unassigned: MVC attribute routing fails for multiple routes with the same URL, and no specific RouteName set. [1146]

$
0
0
__Scenario__:
User decorates the controller and actions with attributed routes and expects the applicaiton to work.

__Issue__:
Consider the following two actions in AccountController(shortened for brevity):
```
[RoutePrefix("Account")]
public class AccountController : Controller
{
//
// GET: /Account/Register
[AllowAnonymous]
[HttpGet("Register")]
public ActionResult Register()


//
// POST: /Account/Register
[HttpPost("Register")]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
}
```
After the above changes, when the application is launched, we currently get the following
__Error__:
"A route named 'Account/Register' is already in the route collection. Route names must be unique.
Parameter name: name"

__Expected__:
The above error should not be occuring and the application should be launched successfully.

__Reason__:
In MVC, it appears that most of the Url link generation happens via the "Url.Action" or "Html.Actionlink" helpers, where users can specify action name, controller name etc. Since these helpers are used more commonly than "Url.RouteUrl" which expects a route name, we should not force the users to supply a unique route name upfront. We should generate unique names automatically just like how Web API's attribute routing works.

Even in Web API, we do not expect the users to depend on our uniquely generated names to generate links. If indeed they would like to have a friendly name for a particular route, they are expected to explicitly supply them. This way at least we do not provide a bad user experience upfront like currently MVC attribute routing does.

Comments: I edited the title to reflect the problem. The solution is a bit different - instead of auto-generating a name, we can simply omit it altogether (route name is not required by the underlying ASP.NET routing mechanism). if a user wants a specific route name, the user will specify it explicitly.

Commented Issue: DefaultBodyModelValidator should use ReferenceEqualityComparer for detecting cycles in object graphs [1024]

$
0
0
DefaultBodyModelValidator.ValidationContext.Visited is a HashSet<object> used to detect and avoid cycles in object graphs during validation. It uses Object equality rather than reference equality.

POSTED entities might be in an inconsistent state and hence their GetHashCode and Equals implementations might be incorrect.

Ideally, when we are doing cycle detecting, we should be checking for reference equality anyways.
Comments: [Fixed](https://aspnetwebstack.codeplex.com/SourceControl/changeset/1b19ae1e5ba4cb2057193b0081978800f176788f)

Edited Issue: DefaultBodyModelValidator should use ReferenceEqualityComparer for detecting cycles in object graphs [1024]

$
0
0
DefaultBodyModelValidator.ValidationContext.Visited is a HashSet<object> used to detect and avoid cycles in object graphs during validation. It uses Object equality rather than reference equality.

POSTED entities might be in an inconsistent state and hence their GetHashCode and Equals implementations might be incorrect.

Ideally, when we are doing cycle detecting, we should be checking for reference equality anyways.

Edited Issue: DefaultBodyModelValidator should use ReferenceEqualityComparer for detecting cycles in object graphs [1024]

$
0
0
DefaultBodyModelValidator.ValidationContext.Visited is a HashSet<object> used to detect and avoid cycles in object graphs during validation. It uses Object equality rather than reference equality.

POSTED entities might be in an inconsistent state and hence their GetHashCode and Equals implementations might be incorrect.

Ideally, when we are doing cycle detecting, we should be checking for reference equality anyways.

Edited Issue: Value validator should swallow exceptions from getters when traversing tree [611]

$
0
0
Otherwise the exception bubbles up and request fails

Created Unassigned: Mvc attribute routing should provide a way to create custom routes and constaints. [1149]

$
0
0
__Scenario__:
User would like to create domain-specific custom routes or add constraints to a route (_note_: not inline constraint) before its added to the route collection.

__Issue__:
Mvc attribute routing extension currently does not provide a way to supply custom RouteBuilder which can be used to perform the above scenario.

__Reason__:
Creating custom routes (domain specific, for example) or custom constraints seem to be a valid scenario, if not common. I think we should provide a way for end users to do this. Currently Web API's extension accepts a HttpRouteBuilder. Also, we need to provide a consistent user experience across MVC and Web API.

The current extensions on MVC attribute routing are:

public static void MapMvcAttributeRoutes(this RouteCollection routes)
public static void MapMvcAttributeRoutes(this RouteCollection routes, IInlineConstraintResolver constraintResolver)
public static void MapMvcAttributeRoutes(this RouteCollection routes, IEnumerable<Type> controllerTypes)
public static void MapMvcAttributeRoutes(this RouteCollection routes, IEnumerable<Type> controllerTypes, IInlineConstraintResolver constraintResolver)

Commented Feature: Add simple support for OData nested paging [1101]

$
0
0
Implement nested paging where every level is paged at the same size.
Comments: [Fixed](https://aspnetwebstack.codeplex.com/SourceControl/changeset/e26e097fcde5d59722e3309ae7453e2adcb29021)

Edited Feature: Add simple support for OData nested paging [1101]

$
0
0
Implement nested paging where every level is paged at the same size.

Closed Issue: Support external creation of IEdmModel [802]

$
0
0
Currently for an IEdmModel to be used with the ODataMediaTypeFormatters, it MUST be built using an ODataModelBuilder. This is because the formatters require an annotation on IEdmEntitySet using a class called EntitySetLinkBuilderAnnotation, and this class is internal.

However there are clearly scenarios where people want to create there own IEdmModel. For example from:
- DbContext
- IDataServiceMetadataProvider

I see a layered solution.

First make EntitySetLinkBuilderAnnotation public, and give it a constructor that doesn't require an EntitySetConfiguration (you don't necessarily have one of those).
Second make the Formatter annotate the model if an EntitySetLinkBuilderAnnotation is not found, this way if a service follows conventions (most do) then you don't need to annotate the IEdmModel you build at all.

The first part has already been completed with this [commit](https://aspnetwebstack.codeplex.com/SourceControl/changeset/bd007387c45bf3f7f1b3b9ced7b476e601190b58)


Edited Issue: [AttributeRouting]Action having multiple attributes should have appropriate method constraints for corresponding route template [969]

$
0
0

For the following action:
```
[HttpPost("api/values/path1")]
[HttpGet("api/values/path2")]
public void DoSomething()
{
}

```

Currently the routes in the collection are like following:

RouteTemplate:
'api/values/path1' (note: __path1__)
Defaults:
Key:controller, Value:Values
Key:action, Value:DoSomething
Constraints:
Key:httpMethod, Value: __POST, GET__


RouteTemplate:
'api/values/path2' (note: __path2__)
Defaults:
Key:controller, Value:Values
Key:action, Value:DoSomething
Constraints:
Key:httpMethod, Value: __POST, GET__


While fixing this issue, also look into the following scenario:

For the following action:
```
[HttpGet("api/values/path1")]
[HttpGet("api/values/path2")]
public void DoSomething()
{
}
```

Currently following is the route information:

RouteTemplate: 'api/values/path1'
Defaults:
Key:controller, Value:Values
Key:action, Value:DoSomething
Constraints:
Key:httpMethod, Value: __GET, GET__

RouteTemplate: 'api/values/path2'
Defaults:
Key:controller, Value:Values
Key:action, Value:DoSomething
Constraints:
Key:httpMethod, Value: __GET, GET__

Commented Issue: [AttributeRouting]Action having multiple attributes should have appropriate method constraints for corresponding route template [969]

$
0
0

For the following action:
```
[HttpPost("api/values/path1")]
[HttpGet("api/values/path2")]
public void DoSomething()
{
}

```

Currently the routes in the collection are like following:

RouteTemplate:
'api/values/path1' (note: __path1__)
Defaults:
Key:controller, Value:Values
Key:action, Value:DoSomething
Constraints:
Key:httpMethod, Value: __POST, GET__


RouteTemplate:
'api/values/path2' (note: __path2__)
Defaults:
Key:controller, Value:Values
Key:action, Value:DoSomething
Constraints:
Key:httpMethod, Value: __POST, GET__


While fixing this issue, also look into the following scenario:

For the following action:
```
[HttpGet("api/values/path1")]
[HttpGet("api/values/path2")]
public void DoSomething()
{
}
```

Currently following is the route information:

RouteTemplate: 'api/values/path1'
Defaults:
Key:controller, Value:Values
Key:action, Value:DoSomething
Constraints:
Key:httpMethod, Value: __GET, GET__

RouteTemplate: 'api/values/path2'
Defaults:
Key:controller, Value:Values
Key:action, Value:DoSomething
Constraints:
Key:httpMethod, Value: __GET, GET__
Comments: Fixed: https://aspnetwebstack.codeplex.com/SourceControl/changeset/f21a1a08d497830d0cf38ac1d9ac54bcf61bdcbe

Edited Issue: [AttributeRouting]Action having multiple attributes should have appropriate method constraints for corresponding route template [969]

$
0
0

For the following action:
```
[HttpPost("api/values/path1")]
[HttpGet("api/values/path2")]
public void DoSomething()
{
}

```

Currently the routes in the collection are like following:

RouteTemplate:
'api/values/path1' (note: __path1__)
Defaults:
Key:controller, Value:Values
Key:action, Value:DoSomething
Constraints:
Key:httpMethod, Value: __POST, GET__


RouteTemplate:
'api/values/path2' (note: __path2__)
Defaults:
Key:controller, Value:Values
Key:action, Value:DoSomething
Constraints:
Key:httpMethod, Value: __POST, GET__


While fixing this issue, also look into the following scenario:

For the following action:
```
[HttpGet("api/values/path1")]
[HttpGet("api/values/path2")]
public void DoSomething()
{
}
```

Currently following is the route information:

RouteTemplate: 'api/values/path1'
Defaults:
Key:controller, Value:Values
Key:action, Value:DoSomething
Constraints:
Key:httpMethod, Value: __GET, GET__

RouteTemplate: 'api/values/path2'
Defaults:
Key:controller, Value:Values
Key:action, Value:DoSomething
Constraints:
Key:httpMethod, Value: __GET, GET__

Commented Issue: Returning related entities when they are null. OData Web API [1134]

$
0
0
If I try to load a related entity which is null, for instance I have my schema as Carrier has many Phones and I retrieved a Phone and I want to load the Carrier but the Carrier is null (which is ok), then I go to my Container and do "LoadProperty(Phone, "Carrier")" I get an exception because on my Web API OData I have GetCarrier in my PhonesController and when it tries to return the Carrier from this Phone which is null it throws the following error:

```
The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; odata=minimalmetadata; streaming=true; charset=utf-8'.
```

With an inner exception of:

```
Cannot serialize a null 'entry'.
```

And a stack trace:

```
at System.Web.Http.OData.Formatter.Serialization.ODataEntityTypeSerializer.WriteObject(Object graph, ODataMessageWriter messageWriter, ODataSerializerContext writeContext)
at System.Web.Http.OData.Formatter.ODataMediaTypeFormatter.<>c__DisplayClassa.<WriteToStreamAsync>b__9()
at System.Threading.Tasks.TaskHelpers.RunSynchronously(Action action, CancellationToken token)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__33.MoveNext()

```
Is this by design or should I be handling this differently?

My controller has the following method:

```
public Carrier GetCarrier([FromODataUri] int key)
{
Phone phone = _context.Phones.Find(key);
if (phone == null)
{
throw ODataErrors.EntityNotFound(Request);
}

return phone.Carrier;
}
```

Or should I change my code to the following:

```
public HttpResponseMessage GetCarrier([FromODataUri] int key)
{
Phone phone = _context.Phones.Find(key);
if (phone == null)
{
throw ODataErrors.EntityNotFound(Request);
}

if(phone.Carrier == null)
return Request.CreateResponse(HttpStatusCode.OK);

return Request.CreateResponse(HttpStatusCode.OK, phone.Carrier);
}
```

By doing this I won't get the error anymore when trying to user LoadProperty even if the related entity is null. Is this the correct way of doing this?

Comments: Looks like WCF DS returns 204 (No Content). You could return the same in your action. ``` public HttpResponseMessage GetCarrier([FromODataUri] int key) { Phone phone = _context.Phones.Find(key); if (phone == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } if(phone.Carrier == null) { throw new HttpResponseException(HttpStatusCode.NoContent); } return Request.CreateResponse(HttpStatusCode.OK, phone.Carrier); } ```

Edited Issue: Returning related entities when they are null. OData Web API [1134]

$
0
0
If I try to load a related entity which is null, for instance I have my schema as Carrier has many Phones and I retrieved a Phone and I want to load the Carrier but the Carrier is null (which is ok), then I go to my Container and do "LoadProperty(Phone, "Carrier")" I get an exception because on my Web API OData I have GetCarrier in my PhonesController and when it tries to return the Carrier from this Phone which is null it throws the following error:

```
The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; odata=minimalmetadata; streaming=true; charset=utf-8'.
```

With an inner exception of:

```
Cannot serialize a null 'entry'.
```

And a stack trace:

```
at System.Web.Http.OData.Formatter.Serialization.ODataEntityTypeSerializer.WriteObject(Object graph, ODataMessageWriter messageWriter, ODataSerializerContext writeContext)
at System.Web.Http.OData.Formatter.ODataMediaTypeFormatter.<>c__DisplayClassa.<WriteToStreamAsync>b__9()
at System.Threading.Tasks.TaskHelpers.RunSynchronously(Action action, CancellationToken token)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__33.MoveNext()

```
Is this by design or should I be handling this differently?

My controller has the following method:

```
public Carrier GetCarrier([FromODataUri] int key)
{
Phone phone = _context.Phones.Find(key);
if (phone == null)
{
throw ODataErrors.EntityNotFound(Request);
}

return phone.Carrier;
}
```

Or should I change my code to the following:

```
public HttpResponseMessage GetCarrier([FromODataUri] int key)
{
Phone phone = _context.Phones.Find(key);
if (phone == null)
{
throw ODataErrors.EntityNotFound(Request);
}

if(phone.Carrier == null)
return Request.CreateResponse(HttpStatusCode.OK);

return Request.CreateResponse(HttpStatusCode.OK, phone.Carrier);
}
```

By doing this I won't get the error anymore when trying to user LoadProperty even if the related entity is null. Is this the correct way of doing this?

Created Issue: Add support to attribute routing for ignoring the route prefix [1150]

$
0
0
AttributeRouting.net has an option for ignoring the route prefix:

```
[RoutePrefix("Prefix")]
public class IgnorePrefixController : Controller
{
[GET("Index")] // => "Prefix/Index"
[GET("NoPrefix", IgnoreRotuePrefix = true)] // => "NoPrefix"
public ActionResult Index() { /* ... */ }
}
```

It's really convenient to be able to add a route for an action without having to worry about existing route prefixes. This is like having absolute and relative URI paths.

Maybe we could use a leading slash as a way to indicate an absolute route path?:
```
[RoutePrefix("Prefix")]
public class IgnorePrefixController : Controller
{
[GET("Index")] // => "Prefix/Index"
[GET("/NoPrefix")] // => "NoPrefix"
public ActionResult Index() { /* ... */ }
}
```


Closed Feature: Add simple support for OData nested paging [1101]

$
0
0
Implement nested paging where every level is paged at the same size.

Closed Issue: Document dependency between EntitySetController.CreateEntity and GetKey methods [842]

$
0
0
If you override CreateEntity and do not override GetKey, you get an obscure error when calling the service:
{
"odata.error":{
"code":"POST requests are not supported.","message":{
"lang":"en-US","value":"Extracting the key from entity instances is not supported for this entity set."
}
}
}
This is because CreateEntity calls GetKey under the covers. The XML Doc comments on CreateEntity should document the dependency and the fact that you have to override both.
Comments: https://aspnetwebstack.codeplex.com/SourceControl/changeset/98ee28c924a0316befe680b41e98fb56493b298a

Created Unassigned: Web Api attribute routing is adding NonAction decorated method to route collection [1151]

$
0
0
__Scenario__:
A user sometimes would like to keep some methods public in his controller but would not like it to be invoked by end users, so he decorates it with [NonAction] attribute.

__Issue__:
In the following scenario, a route is being added to the route collection:
```
[RoutePrefix("api/values")]
public class ValuesController : ApiController
{
[NonAction]
public IEnumerable<string> GetAllValues()
{
return new string[] { "value1", "value2" };
}
}
```
Following would be how the route could look like in the route collection:
config.Routes.MapHttpRoute("routeName", "api/values", new { }, new { }, new { actions = [Values.GetAllValues()] });

__Workaround__:
Create custom route builder deriving from the default one. Override one of the "BuildHttpRoute" methods which provides access to the action descriptor and using it you can check to see if there are any NonAction attributes decorated and if present, ignore adding the route to the route collection.

Closed Issue: [OData]EntityInstanceContext.EntityInstance is obsolete. [1015]

$
0
0
Consider adding back compat support by trying to lazily initialize this property from EntityInstanceContext.EdmObject.

Now that we support $select and $expand, we optimize the query that we generate to include only properties that the user has asked for in the $select query (and entity keys which are required for OData link generation). This means that we might not have an instance of the entity any more, only a partial set of properties of it.

People who have customized their link generation would be broken with this change. They should modify their code to use EdmObject property instead of EntityInstance. Alternatively, we could try to create an instance of the entity from the partial set of the properties that were selected.

Edited Issue: Action invocation fails when attribute routing is used and trace is also enabled [1138]

$
0
0
I have a simple setup which contains ValuesController decorated with attributed routes. I am seeing the following error when tracing is __enabled__.

Attached a standalone katana selfhost repro.

__Configuration & Controller__:
```
public void Configuration(IAppBuilder appBuilder)
{
var config = new HttpConfiguration();

config.MapHttpAttributeRoutes();

config.EnableSystemDiagnosticsTracing();

appBuilder.UseWebApi(config);
}

[RoutePrefix("api/values")]
public class ValuesController : ApiController
{
[HttpGet("")]
public IEnumerable<string> GetAll()
{
return new string[] { "value1", "value2" };
}

[HttpGet("{id}")]
public string GetSingle(int id)
{
return "value";
}
}
```

__Error__:
```
{"Message":"An error has occurred.","ExceptionMessage":"The given key was not present in the dictionary.","ExceptionType":"System.Collections.Generic.KeyNotFoundException","StackTrace":" at System.Collections.Generic.Dictionary`2.get_Item(TKey key)\r\n at System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.FindActionUsingRouteAndQueryParameters(HttpControllerContext controllerContext, ReflectedHttpActionDescriptor[] actionsFound) in c:\\WebstackRuntime\\Runtime\\src\\System.Web.Http\\Controllers\\ApiControllerActionSelector.cs:line 335\r\n at System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectAction(HttpControllerContext controllerContext) in c:\\WebstackRuntime\\Runtime\\src\\System.Web.Http\\Controllers\\ApiControllerActionSelector.cs:line 157\r\n at System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext) in c:\\WebstackRuntime\\Runtime\\src\\System.Web.Http\\Controllers\\ApiControllerActionSelector.cs:line 38\r\n at System.Web.Http.Tracing.Tracers.HttpActionSelectorTracer.<>c__DisplayClass2.<System.Web.Http.Controllers.IHttpActionSelector.SelectAction>b__0() in c:\\WebstackRuntime\\Runtime\\src\\System.Web.Http\\Tracing\\Tracers\\HttpActionSelectorTracer.cs:line 51\r\n at System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEnd(ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Action execute, Action`1 endTrace, Action`1 errorTrace) in c:\\WebstackRuntime\\Runtime\\src\\System.Web.Http\\Tracing\\ITraceWriterExtensions.cs:line 375\r\n at System.Web.Http.Tracing.Tracers.HttpActionSelectorTracer.System.Web.Http.Controllers.IHttpActionSelector.SelectAction(HttpControllerContext controllerContext) in c:\\WebstackRuntime\\Runtime\\src\\System.Web.Http\\Tracing\\Tracers\\HttpActionSelectorTracer.cs:line 44\r\n at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken) in c:\\WebstackRuntime\\Runtime\\src\\System.Web.Http\\ApiController.cs:line 200\r\n at System.Web.Http.Tracing.Tracers.HttpControllerTracer.<ExecuteAsyncCore>d__5.MoveNext() in c:\\WebstackRuntime\\Runtime\\src\\System.Web.Http\\Tracing\\Tracers\\HttpControllerTracer.cs:line 88\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__21`1.MoveNext() in c:\\WebstackRuntime\\Runtime\\src\\System.Web.Http\\Tracing\\ITraceWriterExtensions.cs:line 535\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__0.MoveNext() in c:\\WebstackRuntime\\Runtime\\src\\System.Web.Http\\Dispatcher\\HttpControllerDispatcher.cs:line 69"}
```

Viewing all 7215 articles
Browse latest View live


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