asp.net-core-mvc

Asp.Net core “remember me” persistent cookie not works after deploy

随声附和 提交于 2020-01-01 08:33:30
问题 I've built an MVC Core (Framework) application and I use Identity to login. When I click "Remember me" option all is ok on my develop machine, but after deploy on server machine, "remember me" doesn't maintain login after 30 minutes. I tried to check if cookie expiry date is set and seems to be ok, also on server machine the cookie seems well set. You can see my cookies detail in following image: Can anyone help me to solve this issue? Thanks in advance for your reply :) EDIT: As required by

Asp.Net Core API disable startup complete message

只谈情不闲聊 提交于 2020-01-01 07:58:10
问题 As part of my application I have a .Net Core API project. Unlike most cases where this project would run as its own process, I have the API run in a thread, among others, in a single process. Also for my project, I have implemented a custom logging system to suit my needs. However, I have come across a slight problem. Every time I run my program, once the API starts, this message is printed to the console: Hosting environment: Production Content root path: C:\Users\Path\To\Code Now listening

Get image from wwwroot/images in ASP.Net Core

拈花ヽ惹草 提交于 2020-01-01 06:36:27
问题 I have an image in wwwroot/img folder and want to use it in my server side code. How can I get the path to this image in code? The code is like this: Graphics graphics = Graphics.FromImage(path) 回答1: string path = $"{Directory.GetCurrentDirectory()}{@"\wwwroot\images"}"; 回答2: It would be cleaner to inject an IHostingEnvironment and then either use its WebRootPath or WebRootFileProvider properties. For example in a controller: private readonly IHostingEnvironment env; public HomeController

Referencing another project in .Net Core

一世执手 提交于 2020-01-01 04:48:07
问题 I have 6 projects in a blank solution. I just want to reference a project to another. I have HomeController in Blog.Web projects. I want to access another project's methods like IOrganizationService in Blog.Services projects. How can I use IOrganization's method in HomeController class? For clear insight, please see picture. Red marks show the errors.... 回答1: It looks like you've created everything as web sites, but I suspect that most of those projects should actually be class libraries

Remove a service in ASP.Net Core Dependency Injection [duplicate]

本秂侑毒 提交于 2020-01-01 04:30:08
问题 This question already has answers here : How to remove a default service from the .net core IoC container? (2 answers) Closed 2 years ago . In an Asp.Net MVC Core (early versions, versions 1.0 or 1.1), dependency injection bindings are configured as follow in the Startup.cs class : public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddScoped<IMyService, MyService>(); // ... } } In my applications, I usually have a base Startup class, where generic

Customizing response serialization in ASP.NET Core MVC

跟風遠走 提交于 2019-12-31 15:52:37
问题 Is it possible to customize the way types are serialized to the response in ASP.NET Core MVC? In my particular use case I've got a struct, AccountId , that simply wraps around a Guid : public readonly struct AccountId { public Guid Value { get; } // ... } When I return it from an action method, unsurprisingly, it serializes to the following: { "value": "F6556C1D-1E8A-4D25-AB06-E8E244067D04" } Instead, I'd like to automatically unwrap the Value so it serializes to a plain string: "F6556C1D

How to register custom UserStore & UserManager in DI

烂漫一生 提交于 2019-12-31 13:12:23
问题 Here is my setup: public class ApplicationUser : IdentityUser<Guid> { } public class ApplicationRole : IdentityRole<Guid> { } public class ApplicationUserLogin : IdentityUserLogin<Guid> { } public class ApplicationUserClaim : IdentityUserClaim<Guid> { } public class ApplicationRoleClaim : IdentityRoleClaim<Guid> { } Here is the definition of my UserStore public class ApplicationUserStore : UserStore<ApplicationUser, ApplicationRole, MyContext, Guid> { public ApplicationUserStore(MyContext

ISO UTC DateTime format as default json output format in MVC 6 API response

旧城冷巷雨未停 提交于 2019-12-31 11:32:30
问题 Does anyone know how to configure MVC6's json output to default to a ISO UTC DateTime string format when returning DateTime objects? In WebApi2 I could set the JsonFormatter SerializerSettings and convert datetimes however i'm a bit stuck with how to do this in MVC6 回答1: And I just stumbled onto something that helped me figure it out. Just in case anyone wants to know In your Startup.ConfigureServices services.AddMvc().AddJsonOptions(options => { options.SerializerSettings

Posting files and model to controller in ASP.NET Core MVC6

三世轮回 提交于 2019-12-31 09:59:50
问题 I'm migrating a project from ASP.NET RC1 to ASP.NET Core 1.0. I have a view that allows users to upload one of more files, which I post using Jquery Ajax. I also serialize and post some settings within the same post. The following all worked in RC1 (and pre-asp.net core): Js: $('#submit').click(function () { var postData = $('#fields :input').serializeArray(); var fileSelect = document.getElementById('file-select'); var files = fileSelect.files; var data = new FormData(); for (var i = 0; i <

TagHelpers doesn't get invoked after moving them to a different project

拥有回忆 提交于 2019-12-31 07:06:07
问题 I'm having some issues with asp.net core not finding and invoking my tag helpers. After I moved the taghelpers from a seperate assembly ( LC.Tools.Utility.TagHelpers ) to LC.Tools.Utility it doesnt seem like they get discovered even though the namespace is the same as before. Sample cshtml : <lc:css src="styles.min.css" /> <lc:css src="styles.bootstrap.min.css" /> <lc:css src="styles._layout.min.css" /> When looking at the source for the page the tags are exactly the same. _ViewImports.cshtml