asp.net-core-mvc

Model Binding with ASP.NET Core [duplicate]

喜你入骨 提交于 2020-05-27 13:18:51
问题 This question already has an answer here : Why is Model Binding not working in my POST action method? (1 answer) Closed 2 years ago . I'm trying to make a simple todo MVC application with asp.net core MVC. My plan is to make a webpage with simple checkboxes and give the user the ability to change the state with a form. The form is displayed correctly but the "model binding" in the controller does not work. What am I doing wrong? The UI (image) The view: @model List<Todo> <form asp-controller=

_signInManager.GetExternalLoginInfoAsync() always returns null with open id to azure ad

久未见 提交于 2020-05-27 08:13:10
问题 Why does the signinmanager getexternallogininfoasync method always returning null? I am using VS2015 with the default asp.net core (not framework) project for MVC with individual user accounts (this is a requirement) . The purpose of using third party login is to allow users to self register. Role based authorization will be handled by asp.net identity using the identity provided from registering through Azure AD. Correct me if the following interpretation of the signin in manager is

Get role/s of current logged in user in ASP.NET Core MVC

十年热恋 提交于 2020-05-26 10:17:20
问题 How can I get the logged in user's role/s in ASP.NET Core MVC? I want to get role details as soon as user logs in into the application, but by using following code I am not able to retrieve the role details public async Task<IActionResult> Login(LoginViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure: false); if (result

How do you encrypt a password within appsettings.json for ASP.net Core 2?

时间秒杀一切 提交于 2020-05-26 06:00:46
问题 I'd like to use my appsettings.json to store a "master password". This master password would then be used to open up a private key (and its subsequent password store) generated by this excellent password store package: https://github.com/neosmart/SecureStore The problem is, I can't think of any way to encrypt the master password. I know in .NET 4.5, it was possible to do the following: 1) Place your password into the web.config file 2) Run this script: aspnet_regiis.exe -pef appSettings "C:

How do you encrypt a password within appsettings.json for ASP.net Core 2?

梦想与她 提交于 2020-05-26 06:00:28
问题 I'd like to use my appsettings.json to store a "master password". This master password would then be used to open up a private key (and its subsequent password store) generated by this excellent password store package: https://github.com/neosmart/SecureStore The problem is, I can't think of any way to encrypt the master password. I know in .NET 4.5, it was possible to do the following: 1) Place your password into the web.config file 2) Run this script: aspnet_regiis.exe -pef appSettings "C:

ASP.NET Core—access Configuration from static class

↘锁芯ラ 提交于 2020-05-24 16:43:07
问题 I want a simple static class that accesses the Configuration object. All the config info is already read in from the appsettings.json file in the Startup class. I just need an easy way to access it. Is this possible? namespace MyNamespace { public static class Config { public string Username => Configuration["Username"]; public string Password => Configuration["Password"]; } } Anywhere else in the app: string username = Config.Username; string password = Config.Password; 回答1: A slightly

ASP.net-core 3.0 - Is it possible to return custom error page when user is not in a policy?

北城以北 提交于 2020-05-16 07:51:50
问题 I'm creating an intranet website and I'm having some trouble with the authentication part. I would like to limit the access for a controller to users in a specific Active Directory Roles. If the user is not in the specified Roles, then it should redirect him to a custom error page. Windows authentication is enabled. I've tried the following solutions : I created a custom policy in my ConfigureServices method inside my Startup.cs : ... services.AddAuthorization(options => { options.AddPolicy(

Declare global Razor Page variables in ASP.NET MVC [NOT Static]

谁都会走 提交于 2020-05-15 03:56:05
问题 I have a ConfigurationService class that is injected in "_ViewImports" @inject IConfigurationService ConfigurationService And access it each View Page like below: @{ // Configurations var configuration = await ConfigurationService.GetGeneralConfiguration(); var currencySymbol = configuration.Currency.Symbol; } This works, but each page I have to copy and paste the code. I've tried to write the code in _Layout.cshtml but don't works. Static vars also don't works because the values are not

Implementing GraphQL (GraphQL for .Net) in ASP.NET Core, why is my Query:ObjectGraphType class not being registered by dependency injection?

拈花ヽ惹草 提交于 2020-05-15 00:48:40
问题 I've setup a basic Web Api demonstrate the use of GraphQL using ASP.Net Core. I've Followed a tutorial, what feels like exactly but am getting an error I don't understand. I'm using GraphQL for .NET v2.4.0 This is the error: System.InvalidOperationException: No service for type 'Land.GraphQL.Queries.LandQuery' has been registered. at at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at at GraphQL

asp.net core tilde slash (~/) not resolving image path

≯℡__Kan透↙ 提交于 2020-05-14 05:55:17
问题 I have some markup in my Index.cshtml view, which has an inline css style with the background-image property. When the page is rendered the correct path of the image is not being generated and the tilde remains in the url HTML Markup: The path that is used on the img tag works properly when the page is rendered, but the path in the background-image property displays like this and the image is not found Rendered Markup: <article class="card-item card-item-colored" style="background-image:url(~