asp.net-core-mvc

How do I design the retrieval and processing of all user roles?

旧街凉风 提交于 2019-12-11 18:09:15
问题 I am building an intranet with ASP.NET core 2.0 MVC. All users are part of an active directory. Additionaly I have a MSSQL database with the following tables: Users (Id, FirstName, UserNameAd (unique), ...) Roles (Id, RoleName) UserRoles (User_Id, Role_Id) In my web application I now want to retrieve the roles of a user and store them in the Authentication/Identity Classes of Microsoft in order to use [Authenticate(Roles="Admin")] stuff. I am not sure where I shall put this role-request and

Problems referencing static JavaScript files in wwwroot - .Net Core 2.2 Signalr

北城以北 提交于 2019-12-11 18:00:02
问题 I'm having difficulty referencing the relevant js files for signalr from the wwwroot folder. The paths I need to reference are: wwwroot/lib/@aspnet/signalr/dist/browser/signalr.js wwwroot/js/chat.js Here is my view: @page <div class="container"> <div class="row"> </div> <div class="row"> <div class="col-6"> </div> <div class="col-6"> User..........<input type="text" id="userInput" /> <br /> Message...<input type="text" id="messageInput" /> <input type="button" id="sendButton" value="Send

Generic Method Pagination for All API Controllers, Filter All APIs

若如初见. 提交于 2019-12-11 17:53:52
问题 I am trying to take this API and generalize Pagination, so it can be used for Any of my APIs and Models. How would I conduct this? I placed existing code base below, and want to have applicable to all apis and their getmethods. Researching to modify this function. If Microsoft has built into functionality to support this, I am open to Any other strategies. From Resource (Existing Code only used can be used for 1 Class API): https://dejanstojanovic.net/aspnet/2019/january/filtering-and-paging

How to load partial razor page into razor view

♀尐吖头ヾ 提交于 2019-12-11 17:22:21
问题 I am trying to replace my view components with razor pages but it seems that it's not possible to load a partial razor page because a model is expected to be passed yet it is my understanding that the model for a razor page should be declared in the OnGetAsync method. Here is my code... Razor Page @page "{id:int}" @model _BackgroundModel <form method="POST"> <div>Name: <input asp-for="Description" /></div> <input type="submit" /> </form> Razor Page Code-Behind public class _BackgroundModel :

How to remove default ASP.NET Core Identity endpoints?

风格不统一 提交于 2019-12-11 17:16:21
问题 Let's say I'd want to write my own Login, Logout endpoints and their Views But for some reason I'm struggling hard with removing an existing endpoints Whenever I remove things that probably are associated with those endpoints, then they recreate themselves and return their default Views. Basically I'd want to remove as much as possible default endpoints/views of those generated from ASP.NET Core Identity Any ideas on how can I acheive that? "Templates/Identity/Pages/Account/Account

injectiong an instance of ApplicationModel into an MVC service which will itself be a singleton

老子叫甜甜 提交于 2019-12-11 16:58:35
问题 I would like to display components of a navigation tree only if a principal has access to those components (whether roles or policy based). I am not particularly familiar with MVC core, but reading to date would indicate that I could build a list of what authorization filters will be applied to an action with something like: public NavigationNodePermissionResolver(ApplicationModel appModel) { foreach (var controllerModel in appModel.Controllers) { var contextFilters = controllerModel.Filters

ASP.NET CORE Web API: Model value is null when doing HTTP Post requests with null Guid

无人久伴 提交于 2019-12-11 16:55:40
问题 I'm facing a problem doing post requests via ASP.NET Core Web API. I'm a bit confused of the articles I read/found while Googling. So here's my scenario: I'm trying to do a HTTP Post request to an api endpoint with a complex parameter. [HttpPost] [Route("api/createstudent")] public async Task<ActionResult> CreateStudent([FromBody]Student student) { // Service logic } Model: public class Student { public Guid StudentId { get; set; } public string StudentName { get; set; } } My problem is that

How to avoid not-safe context operations in EF Core? [duplicate]

泪湿孤枕 提交于 2019-12-11 15:55:04
问题 This question already has answers here : Entity Framework Core: A second operation started on this context before a previous operation completed (11 answers) Closed last year . I'd want to know how why creating instances of other classes with current database context instances as a parameter and using that db context causes this exception to be raised 'A second operation started on this context before a previous operation completed. Any instance members are not guaranteed to be thread safe.'

Claims added to ClaimsIdentity getting lost in ASP.NET Core Identity System

旧城冷巷雨未停 提交于 2019-12-11 15:44:04
问题 In my ASP.NET Core Identity I have noticed that my claim that I add are getting lost . First I have a Create claim view having a form to create a claim. The claim is added to the currently logged in user . The code of the Action method is: [HttpPost] [ActionName("Create")] public IActionResult Create_Post(string claimType, string claimValue, string claimIssuer) { ClaimsIdentity identity = User.Identity as ClaimsIdentity; Claim claim = new Claim(claimType, claimValue, ClaimValueTypes.String,

ReflectionTypeLoadException in ASP.NET Core MVC application

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 15:37:28
问题 I'm running into a problem running an ASP.NET Core 1.0 application targeting .NET Framework 4.6. The problem didn't occur until we tried to run the application on a server running Windows Server 2016. The app is hosted in IIS and I have the .NET Core 1.0 Windows Hosting Bundle installed on the server. Upon loading the site a 500 error is returned and this is written to the Logs: An unhandled exception has occurred: Unable to load one or more of the requested types. Retrieve the