Skip to content

Commit 986f6fe

Browse files
committed
Fix RedirectResult for AspNetCore 2.2. Fixes #3986
1 parent afb6042 commit 986f6fe

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

src/WebJobs.Script.WebHost/Middleware/FunctionInvocationMiddleware.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Microsoft.AspNetCore.Http;
1313
using Microsoft.AspNetCore.Http.Features;
1414
using Microsoft.AspNetCore.Mvc;
15+
using Microsoft.AspNetCore.Mvc.Abstractions;
1516
using Microsoft.AspNetCore.Routing;
1617
using Microsoft.Azure.WebJobs.Extensions.Http;
1718
using Microsoft.Azure.WebJobs.Logging;
@@ -62,11 +63,7 @@ public async Task Invoke(HttpContext context)
6263
return;
6364
}
6465

65-
var actionContext = new ActionContext
66-
{
67-
HttpContext = context
68-
};
69-
66+
ActionContext actionContext = new ActionContext(context, new RouteData(), new ActionDescriptor());
7067
await result.ExecuteResultAsync(actionContext);
7168
}
7269
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"bindings": [
3+
{
4+
"type": "httpTrigger",
5+
"name": "req",
6+
"direction": "in",
7+
"methods": [ "get" ],
8+
"authLevel": "anonymous"
9+
},
10+
{
11+
"type": "http",
12+
"name": "$return",
13+
"direction": "out"
14+
}
15+
]
16+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#r "Newtonsoft.Json"
2+
3+
using System.Net;
4+
using Microsoft.AspNetCore.Mvc;
5+
using Microsoft.Extensions.Primitives;
6+
using Newtonsoft.Json;
7+
8+
public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
9+
{
10+
return new RedirectResult("http://bing.com");
11+
}

test/WebJobs.Script.Tests.Integration/WebHostEndToEnd/CSharpEndToEndTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@ public async Task VerifyHostHeader()
150150
Assert.Equal($"{actualProtocol}://{actualHost}/{path}", url);
151151
}
152152

153+
[Fact]
154+
public async Task VerifyResultRedirect()
155+
{
156+
const string path = "api/httptrigger-redirect";
157+
var request = new HttpRequestMessage
158+
{
159+
RequestUri = new Uri(string.Format($"http://localhost/{path}")),
160+
Method = HttpMethod.Get
161+
};
162+
163+
var response = await Fixture.Host.HttpClient.SendAsync(request);
164+
Assert.Equal(response.StatusCode, HttpStatusCode.Redirect);
165+
}
166+
153167
[Fact]
154168
public async Task MultipleOutputs()
155169
{
@@ -406,6 +420,7 @@ public override void ConfigureJobHost(IWebJobsBuilder webJobsBuilder)
406420
"AssembliesFromSharedLocation",
407421
"HttpTrigger-Dynamic",
408422
"HttpTrigger-Scenarios",
423+
"HttpTrigger-Redirect",
409424
"HttpTriggerToBlob",
410425
"FunctionExecutionContext",
411426
"LoadScriptReference",

0 commit comments

Comments
 (0)