dotnet / dotnet/AspNetCore.Docs

[Enhancement] What is the suggestion for TypedResults using e.g. Problem WITH a Redirect?

Open
#36,476 4 comments 0 reactions 1 assignee Claimed by @wadepickett View on GitHub
Dominant language
C#
Stars
13.1k
Forks
24.6k
Avg merge
1d 2h
Merged PRs (30d)
109

Description

### Description

I am looking into the Social Auth sample here:

https://github.com/dotnet/aspnetcore/blob/4b30be10dea772f6c398b68be1506db6b6acf7f2/src/Security/Authentication/samples/SocialSample/Startup.cs#L385-L390

and would like to Upgrade this to TypedResults to ensure type security 🚀
but now I am a bit stuck with how I can combine a `TypedResult.Problem` which I would assume to be the closest to the "regular" `NotSupportedException` we would use on non web targets and the go-to for web is to not throw exceptions then use the return value instead.
The original return has been nothing, but it was also using `.Run(` which I don't see combine-able with `IRouteGroupBuilder` .

What I came up with so far:
```csharp
return TypedResults.Problem(title: $"Provider not supported", detail: "No refresh_token is available.
Home", statusCode:StatusCodes.Status501NotImplemented);
```
As there is no extension for Problem like `.Problem(...).RedirectToRoute("/")` and [`RedirectToRoute`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.typedresults.redirecttoroute?view=aspnetcore-10.0) has no message to add, I would assume that [the `extensions` overload of it could eventually be used for this](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.typedresults.problem?view=aspnetcore-10.0#microsoft-aspnetcore-http-typedresults-problem(system-string-system-string-system-nullable((system-int32))-system-string-system-string-system-collections-generic-idictionary((system-string-system-object)))) ?
But I was unable to find a sample in the current documentation, how I could/should use this 🤔

Could someone recommend something for this to me please and add some note to the docs for others too?

### Page URL

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/error-handling-api?view=aspnetcore-10.0&tabs=minimal-apis

### Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/fundamentals/error-handling-api.md

### Document ID

5ad65468-c51c-9899-c435-6e99d734d0b8

### Platform Id

bc49b255-ac35-3229-e350-58e76d52238c

### Article author

@brunolins16

### Metadata

* ID: 5ad65468-c51c-9899-c435-6e99d734d0b8
* PlatformId: bc49b255-ac35-3229-e350-58e76d52238c
* Service: **aspnet-core**
* Sub-service: **fundamentals**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.