asp.net-core-2.1

How to use UseExceptionHandler in the mvc startup without redirecting the user?

两盒软妹~` 提交于 2020-12-15 03:42:56
问题 I have a ASP.NET Core 2.1 MVC application, and I'm trying to return a separate html view when an exception occurs. The reason for this is that if there are errors, we don't want google to register the redirects to the error page for our SEO (I've omitted development settings to clear things up). Our startup contained this: app.UseExceptionHandler("/Error/500"); // this caused a redirect because some of our middleware. app.UseStatusCodePagesWithReExecute("/error/{0}"); But we want to prevent a

Is it allowed to use Task.Run in an ASP.NET Core controller?

点点圈 提交于 2020-12-13 18:00:23
问题 Scenario: I have a web service with a "Delete" ASP.NET Core controller action. The implementation consists of two steps: one cheap after which other operations can already no longer see the deleted data, and a long-running second step which performs the actual deletion. Is it okay to use Task.Run for the second operation and never await it and so return to the caller very soon? I know that this task could be lost due to application shutdown, but is it even allowed to offload work to the

Is it allowed to use Task.Run in an ASP.NET Core controller?

南楼画角 提交于 2020-12-13 17:59:39
问题 Scenario: I have a web service with a "Delete" ASP.NET Core controller action. The implementation consists of two steps: one cheap after which other operations can already no longer see the deleted data, and a long-running second step which performs the actual deletion. Is it okay to use Task.Run for the second operation and never await it and so return to the caller very soon? I know that this task could be lost due to application shutdown, but is it even allowed to offload work to the

Difference between `MapControllerRoute`, `MapDefaultControllerRoute`, and `MapControllers`?

半腔热情 提交于 2020-12-05 05:00:31
问题 I'm upgrading .NET Core 2.1 to .NET Core 3.0 and I saw here I have to use UseEndpoints . However, at some pages I've seen it with either MapControllerRoute , MapDefaultControllerRoute , or MapControllers . I checked at the documentation and I saw that MapDefaultControllerRoute is basically the same as MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}") . But I don't understand the difference with MapControllers . What does this last function actually do? The documentation

Difference between `MapControllerRoute`, `MapDefaultControllerRoute`, and `MapControllers`?

谁都会走 提交于 2020-12-05 05:00:27
问题 I'm upgrading .NET Core 2.1 to .NET Core 3.0 and I saw here I have to use UseEndpoints . However, at some pages I've seen it with either MapControllerRoute , MapDefaultControllerRoute , or MapControllers . I checked at the documentation and I saw that MapDefaultControllerRoute is basically the same as MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}") . But I don't understand the difference with MapControllers . What does this last function actually do? The documentation

Create text file and download without saving on server in ASP.net Core MVC 2.1

百般思念 提交于 2020-12-01 10:06:28
问题 I've found a way to create a text file then instantly download it in the browser without writing it to the server in regular ASP.net: Create text file and download The accepted answer uses: using (StreamWriter writer = new StreamWriter(Response.OutputStream, Encoding.UTF8)) { writer.Write("This is the content"); } I need to do this in ASP.net Core 2.1 MVC - though in that doesn't know what Response.OutputStream is - and I can't find anything on Google to help with that, or other ways to do

Create text file and download without saving on server in ASP.net Core MVC 2.1

[亡魂溺海] 提交于 2020-12-01 10:04:10
问题 I've found a way to create a text file then instantly download it in the browser without writing it to the server in regular ASP.net: Create text file and download The accepted answer uses: using (StreamWriter writer = new StreamWriter(Response.OutputStream, Encoding.UTF8)) { writer.Write("This is the content"); } I need to do this in ASP.net Core 2.1 MVC - though in that doesn't know what Response.OutputStream is - and I can't find anything on Google to help with that, or other ways to do