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

Edited Unassigned: WebApi deadlock when doing async chunked response [2294]

$
0
0
When running on IIS 7.5 on Server 2008 R2, I've been able to reproduce a deadlock when doing async writes on a chunked response.

For instance:

```
[HttpGet]
public HttpResponseMessage Test()
{
var resp = Request.CreateResponse();
resp.Content = new NeatoHttpContent();
return resp;
}

public class NeatoHttpContent : HttpContent
{
protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
stream.Flush();
var foo = "1234567890";
var bytes = Encoding.ASCII.GetBytes(foo);
for (var i = 0; i < 70000; i++)
{
await stream.WriteAsync(bytes, 0, bytes.Length);
}
}

protected override bool TryComputeLength(out long length)
{
length = 0;
return false;
}
}
```

On the line with the WriteAsync, if I add a ConfigureAwait(false) afterwards, it gets rid of the deadlock. Unfortunately this isn't really practical from my production code since I'm returning an object result which is serializing JSON. Yes, I know I could write my own facade over the http content but that isn't terribly practical.


Commented Unassigned: WebApi deadlock when doing async chunked response [2294]

$
0
0
When running on IIS 7.5 on Server 2008 R2, I've been able to reproduce a deadlock when doing async writes on a chunked response.

For instance:

```
[HttpGet]
public HttpResponseMessage Test()
{
var resp = Request.CreateResponse();
resp.Content = new NeatoHttpContent();
return resp;
}

public class NeatoHttpContent : HttpContent
{
protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
stream.Flush();
var foo = "1234567890";
var bytes = Encoding.ASCII.GetBytes(foo);
for (var i = 0; i < 70000; i++)
{
await stream.WriteAsync(bytes, 0, bytes.Length);
}
}

protected override bool TryComputeLength(out long length)
{
length = 0;
return false;
}
}
```

On the line with the WriteAsync, if I add a ConfigureAwait(false) afterwards, it gets rid of the deadlock. Unfortunately this isn't really practical from my production code since I'm returning an object result which is serializing JSON. Yes, I know I could write my own facade over the http content but that isn't terribly practical.

Comments: Update: after changing to target .net 4.6.1 (I was on 4.5.1), the deadlock appears to be resolved. But no matter what I do, I can't get it to respond with a chunked response. IIS always responds with a "Connection: close" header

Commented Unassigned: WebApi deadlock when doing async chunked response [2294]

$
0
0
When running on IIS 7.5 on Server 2008 R2, I've been able to reproduce a deadlock when doing async writes on a chunked response.

For instance:

```
[HttpGet]
public HttpResponseMessage Test()
{
var resp = Request.CreateResponse();
resp.Content = new NeatoHttpContent();
return resp;
}

public class NeatoHttpContent : HttpContent
{
protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
stream.Flush();
var foo = "1234567890";
var bytes = Encoding.ASCII.GetBytes(foo);
for (var i = 0; i < 70000; i++)
{
await stream.WriteAsync(bytes, 0, bytes.Length);
}
}

protected override bool TryComputeLength(out long length)
{
length = 0;
return false;
}
}
```

On the line with the WriteAsync, if I add a ConfigureAwait(false) afterwards, it gets rid of the deadlock. Unfortunately this isn't really practical from my production code since I'm returning an object result which is serializing JSON. Yes, I know I could write my own facade over the http content but that isn't terribly practical.

Comments: Dang, I read this article: http://www.codeproject.com/Articles/671592/A-tale-of-ASP-NET-IIS-chunked-responses-and-ke And while I had already checked the keep alive settings at the server level, the Default Web Site had keep alives turned off. Sure enough, turning this on made chunked responses come back.

Created Unassigned: RenderAction should be independent of http method [2295]

$
0
0
When using ``` @{ Html.RenderAction("ActionName", "ControllerName") } ``` MVC should return the specified action independent of the current http method.

See http://stackoverflow.com/questions/4227930/renderaction-calls-wrong-action-method and http://stackoverflow.com/questions/16941317/a-public-action-method-was-not-found-on-controller for more information

Reviewed: v5.2.2 (2月 25, 2016)

$
0
0
Rated 5 Stars (out of 5) - Download learning thank you so much

New Post: IHttpActionResult: Why does ExecuteAsync() accept a CancellationToken?

$
0
0
Hi,

I've check all *Result classes under System.Web.Http.Results which implement IHttpActionResult.
None of them seem to do anything with the cancellation token.
Why is the token there at the interface, at all?

Thanks!
Berlo

Reviewed: v4.0 RTM (二月 29, 2016)

$
0
0
Rated 5 Stars (out of 5) - xxxxxxxxxxxxx

Created Unassigned: unable to retrieve object from json when the object name is one object attribute [2296]

$
0
0
Hello,

When you are calling a controller from json, which argument name is one property name of the object. You get an object with every properties at null.

Here is a program which reproduces the problem:
For the asp.net mvc controller:
`
public class Obj
{
public string[] Values { get; set; }
}

[HttpPost]
[Route("Sample")]
public ActionResult Index(Obj values)
{
return Content(string.Join(",", values.Values));
}`

For the testing program, which calls our controller:
` public class Obj
{
public string[] Values { get; set; }
}

static void Main(string[] args)
{
var client = new HttpClient();
var resp = client.PostAsJsonAsync("http://localhost:4093/Sample", new Obj { Values = new string[] { "a", "b" } });
resp.Wait();
var result = resp.Result.Content.ReadAsStringAsync();
result.Wait();
Console.WriteLine(result.Result);
}`
When you run this program, you'll have a null reference exception in the Controller's Index method. This is because the object values is null as there is already a property Values in the object.

I think, this is a bug, are you agree?

I attached a sample reproducing this problem

Created Unassigned: Issue with arrays in expression when using DotNetCompilerPlatform [2297]

$
0
0
I copied this issue from https://github.com/aspnet/Mvc/issues/2890 because it looks like no related issues been tracked by ASP.NET MVC 5 project.

---

Hey, not 100% sure if this an MVC issue or Roslyn issue, but the issue exists when using DotNetCompilerPlatform 1.0.0.0 and MVC 5.2.3.0

The issue is that array variables used in an array get the wrong name (the end up being prefixed with "CS$<>8__locals1.") when used with HtmlHelper expression methods, eg Html.NameFor()

Steps to reproduce:
1. In VS2015 create a new MVC5 project using the ASP.NET 4.6 template "MVC" (which already has Microsoft.CodeDom.Providers.DotNetCompilerPlatform installed)
2. Replace the content /Views/Home/Index.cshtml with the razor code below
3. Start the project and view the result in a browser.

```
@{
Layout = null;

var someArray = new[]
{
new
{
someProperty = ""
}
};
}
```


```
<html>
<body>
@Html.NameFor(_ => someArray[0].someProperty)<br />

@for (var i = 0; i < someArray.Length; ++i)
{
@Html.NameFor(_ => someArray[i].someProperty)<br />
}
</body>
</html>
```

The content of the page looks like the following, when the two rows of the output should be identical.

```
someArray[0].someProperty
CS$<>8__locals1.someArray[0].someProperty
```

Note that commenting out the "system.codedom" section in web.config resolves the issue by essentially disabling the DotNetCompilerPlatform package.

Created Unassigned: Nuget package Microsoft.AspNet.WebHelpers 3.2.3 dependency [2298]

$
0
0
The NuGet package Microsoft.AspNet.WebHelpers 3.2.3 require Microsoft.AspNet.WebPages.Data 3.0.0.0.

If install Microsoft.AspNet.WebHelpers 3.2.3 into a empty visual studio web project directly, it only install Microsoft.AspNet.WebPages.Data 1.0.20105.408.

It cause "Could not load file or assembly 'WebMatrix.Data, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference." error.

Created Unassigned: Let WebMatrix.Data.Database use Localdb to open mdf file [2299]

$
0
0
Database.Open("*") have three action:

1. use the connection string in the Web.config file which name "*" to connect to database
2. use SQL Server Express to access App_Data\*.mdf
3. use SQL Server CE 4.0 to access App_Data\*.sdf

The SQL Server CE is deprecated.
Only SQL Server Express support User Instance, and WebMatrix auto generate the connection string to the default SQL Server Express instance. If I have install a SQL Server Developer, I have to install another default SQL Server Express instance (Data Source=.\SQLEXPRESS) to use Database.Open() to connect to mdf file.

Localdb is a lightweight database then SQL Server Express and Microsoft recommend to use it to develop.

Maybe WebMatrix can use the Localdb to open mdf file, if there is no install default SQL Server Express instance.

New Post: ApiExplorer.ApiDescriptions shows invalid routes

$
0
0
I am working on a self-hosted web api project (.Net 4.5) where we previously only had the default route template mapped ( "api/{controller}/{id}" ). Actions deviating from this were declared with the route attribute. We are using Swashbuckle/Swagger to generate a nice API documentation, and this is based on the ApiDescriptions property on the ApiExplorer class.

So our actions look like this:
...
/api/AuthTokens/ (POST, DELETE)
/api/Customers/(id) (POST,GET,DELETE,PUT)
/api/Orders/(id) (GET)
/api/Orders/(from)/(to)/{id} (GET)
...

Yesterday I added a new route template ("api/{controller}/{from}/{to}/{id}", id optional) to the mapping, before the default route, with the purpose of serving up data for date intervals and then I removed the route attributes from the Orders actions.
This caused our Swagger docs to become all messed up, showing routes/actions that do not exist on several controllers.

It seems ApiExplorer generates ApiDescriptions for the period route for ALL controllers, even those that don't have any matching action methods. So now the documentation looks like we have these actions:
...
/api/AuthTokens/ (POST, DELETE)
/api/AuthTokens/(from)/(to) (GET) <-- no matching action method
/api/AuthTokens/(from)/(to)/(id) (GET) <-- no matching action method
/api/Customers/(id) (POST,GET,DELETE,PUT)
/api/Customers/(from)/(to) (GET) <-- no matching action method
/api/Customers/(from)/(to)/(id) (GET) <-- no matching action method
/api/Orders/(from)/(to) (GET)
/api/Orders/(from)/(to)/{id} (GET)
...

Our route mapping is quite simple:
            HttpConfiguration config = new HttpConfiguration();
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute(
                name: "Period route",
                routeTemplate: "api/{controller}/{from}/{to}/{id}",
                defaults: new
                {
                    id = RouteParameter.Optional
                }, 
                constraints: new 
                {
                    from = @"^\d{4}\-(0?[1-9]|1[012])\-(0?[1-9]|[12][0-9]|3[01])$",
                    to = @"^\d{4}\-(0?[1-9]|1[012])\-(0?[1-9]|[12][0-9]|3[01])$"
                }
            );
            config.Routes.MapHttpRoute(
                name: "Default route",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
Is it the desired behavior that ApiExplorer.ApiDescriptions shows all combinations of controllers and route templates, regardless of the actions actually implemented?
If not, how do I get the ApiExplorer to only show the valid routes?

Reviewed: v5.3 RTM (3月 17, 2016)

$
0
0
Rated 5 Stars (out of 5) - very good!

Created Unassigned: Enable native unobtrusive jquery validation support [2300]

$
0
0
Jquery validation now supports native unobtrusive declarations using data-rule-*, data-msg-*

can you support also that so we don't need the Microsoft.jQuery.Unobtrusive.Validation package?
it contains a a lot of duplicated functionalities of jquery validation framework so if it's facultative an user can remove it when he only needs the core unobtrusive functionalities of native jquery validation

thanks

Commented Unassigned: Unhandled exception is being logged when client cancels requests still happens [2283]

$
0
0
It appears this issue was clsoed for some reason.
http://aspnetwebstack.codeplex.com/workitem/1797

It still happens on 5.2.3 and I posted details back in April of the error it gives. I get these everyday. (I am not using the workaround listed as this was supposed to be fixed)


Comments: Please prioritize this issue we are facing the same issue with asp.net web api 5.2.3

Created Unassigned: ArgumentException when validating OData query with duplicate properties [2301]

$
0
0
My data model has a property called "Name", which is used on several different entities.

```
class Device {
string Name;
}

class User {
string Name;
Device[] Devices;
}
```


When processing a request, we enforce OData validations with:

```
queryOptions.Validate(new ODataValidationSettings
{
AllowedQueryOptions = AllowedQueryOptions.Expand | AllowedQueryOptions.Select
});
```


However, the following $expand causes the Validate Method to throw an Argument Exception:

/Users('some user id')/$expand=Devices($select=Name);$select=Name

The stack trace in question is:

```
System.ArgumentException: An item with the same key has already been added.
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at Microsoft.OData.Edm.Library.EdmNavigationSource.FindNavigationTarget(IEdmNavigationProperty property)
at Microsoft.OData.Edm.Library.EdmContainedEntitySet.FindNavigationTarget(IEdmNavigationProperty property)
at Microsoft.OData.Core.UriParser.Parsers.SelectExpandBinder.GenerateExpandItem(ExpandTermToken tokenIn)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Microsoft.OData.Core.UriParser.Parsers.SelectExpandBinder.BindSubLevel(ExpandToken tokenIn)
at Microsoft.OData.Core.UriParser.Parsers.SelectExpandBinder.GenerateExpandItem(ExpandTermToken tokenIn)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at Microsoft.OData.Core.UriParser.Parsers.SelectExpandBinder.Bind(ExpandToken tokenIn)
at Microsoft.OData.Core.UriParser.Parsers.SelectExpandSemanticBinder.Bind(IEdmStructuredType elementType, IEdmNavigationSource navigationSource, ExpandToken expandToken, SelectToken selectToken, ODataUriParserConfiguration configuration)
at Microsoft.OData.Core.UriParser.ODataQueryOptionParser.ParseSelectAndExpand()
at System.Web.OData.Query.Validators.SelectExpandQueryValidator.Validate(SelectExpandQueryOption selectExpandQueryOption, ODataValidationSettings validationSettings)
at System.Web.OData.Query.Validators.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)
```

Reviewed: v5.2.2 (四月 06, 2016)

$
0
0
Rated 5 Stars (out of 5) - aaaaaaaaaaaaa

Commented Unassigned: Unhandled exception is being logged when client cancels requests still happens [2283]

$
0
0
It appears this issue was clsoed for some reason.
http://aspnetwebstack.codeplex.com/workitem/1797

It still happens on 5.2.3 and I posted details back in April of the error it gives. I get these everyday. (I am not using the workaround listed as this was supposed to be fixed)


Comments: Please let me know in which release you are planning to fix this issue

Commented Issue: Unhandled exception is being logged when client cancels requests [1797]

$
0
0
__Scenario__:
When a user loads a page, it makes one or more ajax requests, which hit ASP.NET Web API 2 controllers. If the user navigates to another page, before these ajax requests complete, the requests are canceled by the browser. (from [here](http://stackoverflow.com/questions/22157596/asp-net-web-api-operationcanceledexception-when-browser-cancels-the-request))

__Issue__:
A long entry is made for each cancelled request.

__Proposed__:
Ignore the exceptions caused due to the cancellation request made by the client.

__Workaround__:
Create a custom message handler which the user could check if the request got cancelled and ignore the cancelled tasks (look [here](http://stackoverflow.com/a/22621596/1184056) for more information):

```
config.MessageHandlers.Add(new CancelledTaskBugWorkaroundMessageHandler());

class CancelledTaskBugWorkaroundMessageHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
HttpResponseMessage response = await base.SendAsync(request, cancellationToken);

// Try to suppress response content when the cancellation token has fired; ASP.NET will log to the Application event log if there's content in this case.
if (cancellationToken.IsCancellationRequested)
{
return new HttpResponseMessage(HttpStatusCode.InternalServerError);
}

return response;
}
}

```

__Attached__ a repro web application.

Comments: I have this issue too with asp.net web api 5.2.3 Please prioritize this issue we are facing the same issue with asp.net web api 5.2.3 and Let me know in which release you are planning to fix this issue

Commented Issue: Unhandled exception is being logged when client cancels requests [1797]

$
0
0
__Scenario__:
When a user loads a page, it makes one or more ajax requests, which hit ASP.NET Web API 2 controllers. If the user navigates to another page, before these ajax requests complete, the requests are canceled by the browser. (from [here](http://stackoverflow.com/questions/22157596/asp-net-web-api-operationcanceledexception-when-browser-cancels-the-request))

__Issue__:
A long entry is made for each cancelled request.

__Proposed__:
Ignore the exceptions caused due to the cancellation request made by the client.

__Workaround__:
Create a custom message handler which the user could check if the request got cancelled and ignore the cancelled tasks (look [here](http://stackoverflow.com/a/22621596/1184056) for more information):

```
config.MessageHandlers.Add(new CancelledTaskBugWorkaroundMessageHandler());

class CancelledTaskBugWorkaroundMessageHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
HttpResponseMessage response = await base.SendAsync(request, cancellationToken);

// Try to suppress response content when the cancellation token has fired; ASP.NET will log to the Application event log if there's content in this case.
if (cancellationToken.IsCancellationRequested)
{
return new HttpResponseMessage(HttpStatusCode.InternalServerError);
}

return response;
}
}

```

__Attached__ a repro web application.

Comments: I'm getting this too. In my case the Cancellation token is setup *within* the webapi controller method, and set to cancel after xx seconds. So, the webapi itself if cancelling the request if it's taking too long (we depend on downstream systems so cancel if they are not responding in time). When the cancellation token fires, the webapi call is cancelled but the global exception handler (implementation of IExceptionHandler) is not fired at all. We get a 500 and then an unhandled ASP.NET exception in the Even Log. WebApi 5.2.3
Viewing all 7925 articles
Browse latest View live


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