asp.net-core-mvc

storing passwords in sql server database using ef core code first

微笑、不失礼 提交于 2019-12-02 02:48:05
问题 I have this class to represent my users: public class User { public int ID {get; set;} public string UserName {get; set;} [DataType(DataType.Password)] public string Password {get; set;} } A simplistic version of my register method looks like this: [HttpPost] Register(User newUser) { ... _context.add(newUser); await _context.SaveChangesAsync(); ... } So my question is: Should I alter the password type from a regular string before storing? If so, to what data type? 回答1: YES YES YES Never store

ASP.NET Core authentication cookie only received once

霸气de小男生 提交于 2019-12-02 02:32:28
I am developing an application with ASP.NET Core and I am using a custom Cookie Authentication. My CookieAuthenticationOptions are: app.UseCookieAuthentication(new CookieAuthenticationOptions() { AuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme, LoginPath = new PathString("/login"), AccessDeniedPath = new PathString("/unauthorized/"), AutomaticAuthenticate = true, AutomaticChallenge = true }); The cookie is created just fine and I can see it in the browser settings throughout the whole time I am running the application. This is my HomeController class: public

How to use ConfigurationBinder in Configure method of startup.cs

被刻印的时光 ゝ 提交于 2019-12-02 02:19:27
asp.net mvc 6 beta5 I've tried to use config.json to activate\disactive logging public IConfiguration Configuration { get; set; } public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) { var configurationBuilder = new ConfigurationBuilder(appEnv.ApplicationBasePath) .AddJsonFile("config.json") .AddEnvironmentVariables(); Configuration = configurationBuilder.Build(); DBContext.ConnectionString = Configuration.Get("Data:DefaultConnection:ConnectionString"); } public void ConfigureServices(IServiceCollection services) { services.AddOptions(); services.Configure<AppSettings>

ASP.Net Core unit testing async controller [duplicate]

99封情书 提交于 2019-12-02 02:13:57
问题 This question already has answers here : How to mock an async repository with Entity Framework Core (4 answers) Closed 4 months ago . I have this test: [Fact] public async void Can_Paginate() { //fake data var product1 = new Product { ProductId = 1, ProductName = "P1" }; var product2 = new Product { ProductId = 2, ProductName = "Product 2" }; var product3 = new Product { ProductId = 3, ProductName = "Product 3" }; var product4 = new Product { ProductId = 4, ProductName = "Product 4" }; var

ASP.NET MVC Core Cascading DropDownList

一笑奈何 提交于 2019-12-02 02:01:29
问题 I'm having trouble finding a tutorial / video that shows how to implement Cascading DropDownList from a Database using EntityFramework. I'm using ASP.NET MVC Core, EntityFramework Core with C#. As of now, I'm able to retrieve the data from my database to my 3 DropDownList fine. What I would like to be able to accomplish is to have the user select a State first which would then display all Cities related to that State. Then after user has selected a City it would display the Zip Code(s)

storing passwords in sql server database using ef core code first

自古美人都是妖i 提交于 2019-12-02 01:52:17
I have this class to represent my users: public class User { public int ID {get; set;} public string UserName {get; set;} [DataType(DataType.Password)] public string Password {get; set;} } A simplistic version of my register method looks like this: [HttpPost] Register(User newUser) { ... _context.add(newUser); await _context.SaveChangesAsync(); ... } So my question is: Should I alter the password type from a regular string before storing? If so, to what data type? YES YES YES Never store passwords as plain text While much of this is a security discussion rather than a programming one, you

ASP.NET Core authentication cookie only received once

妖精的绣舞 提交于 2019-12-02 01:49:37
问题 I am developing an application with ASP.NET Core and I am using a custom Cookie Authentication. My CookieAuthenticationOptions are: app.UseCookieAuthentication(new CookieAuthenticationOptions() { AuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme, LoginPath = new PathString("/login"), AccessDeniedPath = new PathString("/unauthorized/"), AutomaticAuthenticate = true, AutomaticChallenge = true }); The cookie is created just fine and I can see it in the browser settings

Bind netcore IConfigurationSection to a dynamic object

倾然丶 夕夏残阳落幕 提交于 2019-12-02 01:38:11
问题 In my appSettings.json, I have a configuration section that can contain anything as long as it's json valid. It is usally a set of key/value (string/string) I would like to get it in my code and return it in a controller call. I took a look at the source code (https://github.com/aspnet/Configuration/blob/6d9519622b5db2c5ac6bafa8bcdb25fe27914de3/src/Config.Binder/ConfigurationBinder.cs ) and it seems I am doomed with off-the-shelves solutions. If I limit the use case to key value pairs, I can

Compatibility between dotnetcore and framework 4.5

早过忘川 提交于 2019-12-02 01:34:41
问题 I'm adding a new dotnetcore (RC2) project to my existing solution which contains a set of dotnet framewotk 4.5 projects. When I try to add a reference in my brand new dotnetcore project I get a message telling me that I can't do a reference from a project that targets framework 4.5. The following projects are not supported references: "project name" has target frameworks that are incompatible with targets in current project "project name" I followed this thread but I didn't find any clear

How to redirect after Azure AD authentication to different controller action in ASP Net Core MVC

家住魔仙堡 提交于 2019-12-02 01:30:19
I have setup my ASP Net Core 2.0 project to authenticate with Azure AD (using the standard Azure AD Identity Authentication template in VS2017 which uses OIDC). Everything is working fine and the app returns to the base url (/) and runs the HomeController.Index action after authentication is successful. However I now want to redirect to a different controller action (AccountController.CheckSignIn) after authentication so that I can check if the user already exists in my local database table and if not (ie it's a new user) create a local user record and then redirect to HomeController.Index