asp.net-core-2.1

How to replace MVC HomeController/Index redirects with RazorPages routings?

。_饼干妹妹 提交于 2019-12-13 19:04:50
问题 I'm migrating from ASP MVC Classic to ASP Razor Pages. Only one controller left to "migrate": HomeController public class HomeController : Controller { UserManager<WebUser> _userManager; public HomeController(UserManager<WebUser> _userManager) { this._userManager = _userManager; } [Authorize] public async Task<IActionResult> Index() { var user = await _userManager.GetUserAsync(User); if (user == null) { return RedirectToPage("/Account/Login", new { area = "WebUserIdentity" }); } return

How to protect static folder in asp.net core 2.1 using claims-based authorization

孤人 提交于 2019-12-13 16:04:45
问题 I have a small project which uses asp.net core 2.1. I wish to protect folder full of static assets. I tried to implement is based on this article https://odetocode.com/blogs/scott/archive/2015/10/06/authorization-policies-and-middleware-in-asp-net-5.aspx I am using cookies and claims-based authorization. All view which are supposed to check authorization work fine... except static folder. When I check httpContext.User it is missing all expected claims. Middleware: public class ProtectFolder {

Core 2.1 refuses to respond with Access-Control-Expose-Headers: *

巧了我就是萌 提交于 2019-12-13 12:07:13
问题 I must be doing something wrong here but I can't figure it out; it seems to be a CORS issue from what I can tell. I need to expose Access-Control-Expose-Headers: * to any origin but dotnet core 2.1 isn't doing what I expect. Relevant Startup.cs code: public void ConfigureServices(IServiceCollection services) { //Mapping settings to POCO and registering with container var settings = new AppSettings.ReportStorageAccountSettings(); Configuration.Bind(nameof(AppSettings

Problems with @using Microsoft.JSInterop in Blazor applications

二次信任 提交于 2019-12-13 11:06:05
问题 I have a client screen that I created using Razor View, it only has all CRUD options. The problem is when I create or change an account's ALL VIEW VIEW of Loading ... and this is not correct. Only Delete works perfectly, when I delete a client, only the registration table is updated The Controller was created with the Entity Framework option: API Controller with actions, using Entity Famework See the code for my Razor View. @using TesteBlazor.Shared @using TesteBlazor.Shared.Models @page "

ASP.Net Core 2.1 MVC SelectList in View is not getting populated

﹥>﹥吖頭↗ 提交于 2019-12-13 08:06:40
问题 I am working on an ASPNet Core 2.1 MVC website and I am trying to get a select list to populate with a list of Companies (value = Id, text = CompanyName). I can see that the data exists in the List in the ViewModel but no matter what I try, I can't get the data to show in the dropdown list in the view. I am following the first variation of the SelectList recommendation from this SO post Here is my EditSite ViewModel class public class EditSite { public int Id { get; set; } [Required]

.Net Core 2.1 and Angular 6 Cookies

泄露秘密 提交于 2019-12-13 03:48:57
问题 I have a little private Project and now I'm hanging with cookies. First of all I want to show you some code: UserServiceControler.cs [HttpPost("IsAuthenticated")] public IActionResult IsAuthenticated([FromBody] IsAuthenticatedRequest request) { var hash = _userService.IsAuthenticated(HttpContext, request); switch (hash) { case "200": case "401": return new StatusCodeResult(Convert.ToInt32(hash)); default: if (HttpContext.Request.Cookies.Contains("TEST")) { HttpContext.Response.Cookies.Delete(

UseLibuv option gone after changing Microsoft.aspnetcore.all to Microsoft.NETCore.App in .net core 2.1.6

末鹿安然 提交于 2019-12-13 03:31:08
问题 I am using asp.net core 2.1.6 I have just changed my Microsoft.aspnetcore.all to Microsoft.NETCore.App as publishing the web api project is making too much size. In my code i were using use UseLibuv(o => o.ThreadCount = 1000) to set minmum thread count public static IWebHostBuilder BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<StartupShutdownHandler>() //.UseLibuv(o => o.ThreadCount = 1000) ; Now this option is not coming. How can i set min threads now like old

URL rewriting in ASP.NET Core 2.1 without regex

天大地大妈咪最大 提交于 2019-12-12 21:36:37
问题 My favicon is at /images/favicon.ico rather than the root. In Startup.cs I can added a redirect to avoid a 404: app.UseRewriter(new RewriteOptions() .AddRedirect("favicon.ico", "images/favicon.ico")); That works nicely, but of course relies on a redirect. The docs also show how to use rewriting, so the user doesn't see a redirect. I tried this, but get a 404: app.UseRewriter(new RewriteOptions() .AddRewrite("favicon.ico", "images/favicon.ico", skipRemainingRules:true)); So I thought that

SignalR Core - StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1

北城以北 提交于 2019-12-12 16:30:45
问题 I have two projects. First, WebApi that contains Hub for using SignalR : public class NotificationsHub : Hub { public async Task GetUpdateForServer(string call) { await this.Clients.Caller.SendAsync("ReciveServerUpdate", call); } } I set up that Hub in Startup.cs : public void ConfigureServices(IServiceCollection services) { // ofc there is other stuff here services.AddHttpContextAccessor(); services.AddSignalR(); } public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app

SignInManager.PasswordSignInAsync() succeeds, but User.Identity.IsAuthenticated is false

依然范特西╮ 提交于 2019-12-12 09:07:20
问题 I'm new to ASP.Net Core and trying to create an user authentication system. I'm using ASP.Net Core Identity user management. I have the below code for logging in an user. /Areas/Identity/Pages/Account/Login.cshtml.cs public async Task<IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, set