asp.net-core-2.1

ASP.NET core 2.1 session

泪湿孤枕 提交于 2019-11-27 02:40:41
问题 In ASP.NET core 2.1, I cannot access session variables. While debugging I have noticed that in every request the session ID changes (HttpContex.Session.Id) Did I make mistake in session configuration? Startup.cs public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices

ASP.NET Core 2.1 + Kestrel (How to disable HTTPS)

北慕城南 提交于 2019-11-27 01:26:35
问题 So it appears with the advent of ASP.NET Core 2.1, Kestrel now automatically creates an HTTPS endpoint along side the HTTP one, and default project templates are setup to redirect from HTTP to HTTPS (which is easy enough to undo). However my question is... how can I disable HTTPS entirely for my project. I've read through the docs and played with a variety of config settings for HTTPS but nothing I do seems to allow me to turn it off and just run an HTTP project. Am I crazy or just missing

Configure HttpClientFactory to use data from the current request context

僤鯓⒐⒋嵵緔 提交于 2019-11-26 23:09:17
问题 With the new HttpClientFactory in ASP.NET Core 2.1, it's quite easy to configure custom HTTP clients with things like base urls, default headers etc. However, I haven't found a way to centralize configuration that lets me inject headers from the current request context. For example, consider a service called with an Authorization header, which I wish to pass on to all the underlying services as well. It would be awesome to be able to configure this in the .AddHttpClient() call on services in

Identity in ASP.Net Core 2.1 : Customize AccountController

别来无恙 提交于 2019-11-26 22:04:23
I have installed ASP.NET Core 2.1 but even though I have created a new ASP.NET Core Web Application using ASP.NET Core 2.1 with Individual User Accounts → Store user accounts in-app I can't find the AccountController or Views. I can still register and login without a problem but I can't find the code for it, it were present in 2.0. One of the improvements in 2.1 was Razor Class Libraries and the default identity lives in one of these in the individual auth templates. If you would like to have the code in your app so you can customize it, you can scaffold it out with Visual Studio, or with the

Routing is not working with self-hosted web API [duplicate]

冷暖自知 提交于 2019-11-26 20:58:11
问题 This question already has an answer here : WebApi giving 404 whilst debugging; works when published (1 answer) Closed 4 months ago . This is essentially what I have, a very simple set of three files with fresh asp.net core 2.1 (actually copy-pasted from tutorials): public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup

Integration and unit tests no longer work on ASP.NET Core 2.1 failing to find assemblies at runtime

守給你的承諾、 提交于 2019-11-26 19:28:43
问题 When creating test projects or upgrading an application and tests to ASP.NET Core 2.1 / .NET Core 2.1, running tests fails with assembly load exceptions like System.IO.FileNotFoundException : Could not load file or assembly 'Microsoft.AspNetCore, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. When adding references to some other libraries there are also build warnings like warning MSB3277: Found conflicts between different

How to mock the new HttpClientFactory in .NET Core 2.1 using Moq

怎甘沉沦 提交于 2019-11-26 17:03:24
问题 .NET Core 2.1 comes with this new factory called HttpClientFactory , but I can't figure out how to mock it to unit test some methods that include REST service calls. The factory is being injected using .NET Core IoC container, and what the method does is create a new client from the factory: var client = _httpClientFactory.CreateClient(); And then using the client to get data from a REST service: var result = await client.GetStringAsync(url); 回答1: The HttpClientFactory is derived from

How to specify the view location in asp.net core mvc when using custom locations?

坚强是说给别人听的谎言 提交于 2019-11-26 12:24:15
问题 Let\'s say I have a controller that uses attribute based routing to handle a requested url of /admin/product like so: [Route(\"admin/[controller]\")] public class ProductController: Controller { // GET: /admin/product [Route(\"\")] public IActionResult Index() { return View(); } } Now let\'s say that I\'d like to keep my views organized in a folder structure that roughly reflects the url paths they are related to. So I\'d like the view for this controller to be located here: /Views/Admin

Setting the default value of a DateTime Property to DateTime.Now inside the System.ComponentModel Default Value Attrbute

匆匆过客 提交于 2019-11-26 10:29:57
问题 Does any one know how I can specify the Default value for a DateTime property using the System.ComponentModel DefaultValue Attribute? for example I try this: [DefaultValue(typeof(DateTime),DateTime.Now.ToString(\"yyyy-MM-dd\"))] public DateTime DateCreated { get; set; } And it expects the value to be a constant expression. This is in the context of using with ASP.NET Dynamic Data. I do not want to scaffold the DateCreated column but simply supply the DateTime.Now if it is not present. I am