Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi part form async error reproduction #1114

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@
<OutputType>Library</OutputType>
<RootNamespace>AspNetFullFrameworkSampleApp</RootNamespace>
<AssemblyName>AspNetFullFrameworkSampleApp</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<RuntimeIdentifier>win</RuntimeIdentifier>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition="'$(OS)' == 'WINDOWS_NT'">
<AppDesignerFolder>Properties</AppDesignerFolder>
<MvcBuildViews>false</MvcBuildViews>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
Expand Down Expand Up @@ -70,11 +75,7 @@
<Reference Include="System.Web.Entity" />
<Reference Include="System.Web.ApplicationServices" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Web.Abstractions" />
<Reference Include="System.Web.Routing" />
<Reference Include="System.Xml" />
Expand Down Expand Up @@ -305,6 +306,17 @@
<Version>5.0.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<None Include="Properties\PublishProfiles\IISProfile.pubxml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NETStandard.Library">
<Version>2.0.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Include="CustomWebHostBufferPolicySelector.cs" />
</ItemGroup>
<PropertyGroup Condition="'$(OS)' == 'WINDOWS_NT'">
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
Expand All @@ -330,7 +342,6 @@
<IISExpressUseClassicPipelineMode />
<UseGlobalApplicationHostFile />
</PropertyGroup>

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" Condition="'$(OS)' == 'WINDOWS_NT'" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="'$(OS)' == 'WINDOWS_NT' AND Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(OS)' == 'WINDOWS_NT' AND Exists('$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets')" />
Expand All @@ -347,8 +358,6 @@
<DevelopmentServerPort>51565</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost/Elastic.Apm.AspNetFullFramework.Tests.SampleApp</IISUrl>
<OverrideIISAppRootUrl>false</OverrideIISAppRootUrl>
<IISAppRootUrl>http://localhost:51565</IISAppRootUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,35 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using System.IO;

namespace AspNetFullFrameworkSampleApp.Controllers
{
[RoutePrefix(Path)]
public class WebApiController : ApiController
{
public const string Path = "api/WebApi";

[Route]
[HttpGet]
public WebApiResponse Get() =>
new WebApiResponse { Content = "This is an example response from a web api controller" };

[Route]
[HttpPost]
public async Task<IHttpActionResult> Post()
{
var multipart = await Request.Content.ReadAsMultipartAsync(); //exception gets thrown here
var result = string.Empty;
foreach(var content in multipart.Contents)
{
result += await content.ReadAsStringAsync();
}
return Ok(result);
}
}

public class WebApiResponse
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http.WebHost;

namespace AspNetFullFrameworkSampleApp
{
public class CustomWebHostBufferPolicySelector : WebHostBufferPolicySelector
{
public override bool UseBufferedInputStream(object hostContext)
{
System.Web.HttpContextBase contextBase = hostContext as System.Web.HttpContextBase;
if (contextBase != null && contextBase.Request.ContentType != null && contextBase.Request.ContentType.Contains("multipart")) return false;
else return base.UseBufferedInputStream(hostContext);
}

public override bool UseBufferedOutputStream(System.Net.Http.HttpResponseMessage response)
{
return base.UseBufferedOutputStream(response);
}
}
}
3 changes: 3 additions & 0 deletions sample/AspNetFullFrameworkSampleApp/Global.asax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Web;
using System.Web.Http;
using System.Web.Http.Batch;
using System.Web.Http.Hosting;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
Expand Down Expand Up @@ -45,6 +46,8 @@ protected void Application_Start()

ValueProviderFactories.Factories.Remove(ValueProviderFactories.Factories.OfType<JsonValueProviderFactory>().FirstOrDefault());
ValueProviderFactories.Factories.Add(new JsonNetValueProviderFactory());

GlobalConfiguration.Configuration.Services.Replace(typeof(IHostBufferPolicySelector), new CustomWebHostBufferPolicySelector());
}

protected void Application_BeginRequest(object sender, EventArgs e)
Expand Down
Loading