asp.net-core-mvc

Alternative of thread.Abort() in Asp.net Core?

纵然是瞬间 提交于 2021-01-29 07:28:41
问题 Is there any alternative option for thread.Abort() in asp.net core as it no longer support with .Core. // Exceptions: // T:System.PlatformNotSupportedException: // .NET Core only: This member is not supported. This is throw PlatformNotSupportedException exception. I used thread.Interrupt() but it not work as per expectation. 回答1: Thread.Abort() has been removed, since it could not be reliably ported to all platforms and in general poses a threat to the entire app domain, when used incorrectly

Redirecting while using PathBase

回眸只為那壹抹淺笑 提交于 2021-01-29 07:12:45
问题 I have defined PathBase like new PathString("/test_environment/"); Then I'm at https://localhost:5001/test_environment/Login and after login it redirects to /MyController/ Everything works properly - the controller and its method is reached and serves data properly, but my url in browser is: https://localhost:5001/MyController/ It works fine, but where did /test_environment/ go? MyMethod in MyController has an [Route("/")] attribute 回答1: For app.UsePathBase , it adds a middleware that

Get data from JsonResult

依然范特西╮ 提交于 2021-01-29 06:30:40
问题 The code is in ASP.NET Core. MVC controller returns Json(someData). I am trying to retrieve the data in the Unit test. The best I can do is to have string data = JsonConvert.SerializeObject(jsonResult.Value); and then compare the string. But I would prefer to get an object or an array to be able to do some more specific comparisons. Interesting, under debugger I can see that jsonResult.Value is of type Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable<MyType> and there is even

415 Status When Passing Model into Controller Action in ASP.NET Core 3.1 MVC

瘦欲@ 提交于 2021-01-29 05:31:03
问题 I've seen many tutorials and documentation pass the model as an argument in an Action in a controller. Every time I do this I get a 415 status error (incorrect media type) when the action is called. This is problematic for me because my fields clear after the action occurs. Many have suggested calling the model when I return the View, but that has not been working for me. Does anyone know why that is and how I can fix it? I'm so frustrated I've tried so many things and it just never works :(

Area is not passed to Url.Action() in ASP.net Core

爷,独闯天下 提交于 2021-01-29 05:25:24
问题 The following code is working in normal ASP.net MVC. Url.Action("actionName", "controllerName", new { Area = "areaName" }); But it is not work well in ASP.net Core. Area is recognized as a query string parameter. How can I solve it? Thanks for any help. 回答1: Make sure you're registering routes as below : app.UseMvc(routes => { routes.MapRoute( name: "areaRoute", // if you don't have such an area named as `areaName` already, // don't make the part of `{area}` optional by `{area:exists}`

Write to DB after Controller has been disposed

瘦欲@ 提交于 2021-01-29 02:58:52
问题 Situation We have a controller where users can submit any number of E-Mail addresses to invite other (potential) members as friends. If an address is not found in the database, we send an E-Mail message to that user. Since the user does not has to wait for this process to complete in order to continue working this is done asynchronously. Sending E-Mails can take a long time if servers respond slowly, are down or overloaded. The E-Mail sender should update the database according to the status

How do i map user connection and user id in signalr so that i can send a message to a specific user

放肆的年华 提交于 2021-01-29 02:26:00
问题 I want to send a private message to a user, i have created a hub but unfortunately i have no idea how to do it in signalr core, the documentation also doesn't have any article in it. 回答1: How do i map user connection and user id in signalr so that i can send a message to a specific user To achieve above requirement, please refer to the following example. ChatHub class: public class ChatHub : Hub { public static List<KeyValuePair<string, string>> ConnectedIds = new List<KeyValuePair<string,

How do i map user connection and user id in signalr so that i can send a message to a specific user

喜欢而已 提交于 2021-01-29 02:20:45
问题 I want to send a private message to a user, i have created a hub but unfortunately i have no idea how to do it in signalr core, the documentation also doesn't have any article in it. 回答1: How do i map user connection and user id in signalr so that i can send a message to a specific user To achieve above requirement, please refer to the following example. ChatHub class: public class ChatHub : Hub { public static List<KeyValuePair<string, string>> ConnectedIds = new List<KeyValuePair<string,

How to show checked radio button in Razor edit view Asp net core mvc

谁说胖子不能爱 提交于 2021-01-28 23:31:42
问题 Despite of Asp net core code in Razor view: @model List<SelectListItem> <form asp-controller="Manage" asp-action="Change" method="post"> @foreach (SelectListItem item in Model) { <br /> <input asp-for="@item.Value" type="radio" value="@item.Value" /> @(item.Value + " - " + item.Text) } <br /> <input type="submit" value="OK" /> </form> all radio buttons are checked in browser -> view source <input type="radio" value="1001" checked="checked" id="item_Value" name="item.Value" /> 1001 - Vilnius

How to show checked radio button in Razor edit view Asp net core mvc

旧巷老猫 提交于 2021-01-28 23:13:35
问题 Despite of Asp net core code in Razor view: @model List<SelectListItem> <form asp-controller="Manage" asp-action="Change" method="post"> @foreach (SelectListItem item in Model) { <br /> <input asp-for="@item.Value" type="radio" value="@item.Value" /> @(item.Value + " - " + item.Text) } <br /> <input type="submit" value="OK" /> </form> all radio buttons are checked in browser -> view source <input type="radio" value="1001" checked="checked" id="item_Value" name="item.Value" /> 1001 - Vilnius