asp.net-core-2.0

Dapper is throwing System.Data.SqlClient.SqlConnection exception after upgrading System.Data.SqlClient to version 4.5.0-preview2

三世轮回 提交于 2019-12-24 00:38:04
问题 I recently upgraded one of my ASP.NET Core applications from a net461 app to ASP.NET Core 2.0 app since the only thing that was holding me back in the past was System.Transactions (which is now supported). After upgrading I get an error when accessing any function that is using the following: protected static TransactionScope GetTransactionScope() { TransactionOptions transactionOptions = new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted, Timeout =

Logout user after inactivity in asp.net core

不想你离开。 提交于 2019-12-24 00:27:46
问题 I am new to asp.net core. I am trying to implement User Logout after being inactive for a period of time. Can someone suggest guide/tutorial or explain how to implement this using asp.net core 2.0 and MySql instead of Entity Framework. 回答1: After configuring your identity in the services using AddIdentity or AddDefaultIdentity you can configure your cookie ExpireTimeSpan You could read Cookie Settings block in the linked article. services.ConfigureApplicationCookie(options => { options

How to correctly setup Policy Authorization for WEB API in .NET Core

让人想犯罪 __ 提交于 2019-12-23 23:01:49
问题 I have this Web API project, with no UI. My appsettings.json file has a section listing tokens and which client they belong to. So the client will need to just present a matching token in the header. If no token is presented or an invalid one, then it should be returning a 401. In ConfigureServices I setup authorization .AddTransient<IAuthorizationRequirement, ClientTokenRequirement>() .AddAuthorization(opts => opts.AddPolicy(SecurityTokenPolicy, policy => { var sp = services

Changing default action doesn't work for ASP.NET Core 2

Deadly 提交于 2019-12-23 22:50:16
问题 On latest ASP.NET MVC CORE 2 default template, i am trying to change default action by modifying controller and action as below. I am expecting to see login page as default but i am having 404 http error. What I am doing wrong ? You can verify this issue on default ASP.NET CORE 2 MVC project. app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Account}/{action=Login}/{id?}"); }); } 回答1: If you look at the AccountController class, you'll see it's decorated with a

Login redirect with asp.Core 2.0 and React

◇◆丶佛笑我妖孽 提交于 2019-12-23 21:35:17
问题 I've got a component from sample project that comes along when creating new React application with VS - FetchData . It's routed like <Route path='/fetchdata/:startDateIndex?' component={ FetchData } /> and basically what it does is a call to the SampleDataController retrieving generated information about weather IEnumerable<WeatherForecast> WeatherForecasts(int startDateIndex) . By default it's all great, but I want to see how React works with authentication. So I've fixed that controller

Issue Using Custom Index.Html in Swagger / Swashbuckle for .NET Core

橙三吉。 提交于 2019-12-23 19:48:27
问题 I am having difficulty using a custom index.html and other assets with swashbuckle. Swashbuckle/Swagger do not seem to recognizing or using them at all. I do have app.UseDefaultFiles() and app.UseStaticFiles() set. I am trying to understand what I am doing incorrectly. I have attempted to set up my configuration somewhat similar to what is defined on the Microsoft article without success. (https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-help-pages-using-swagger?tabs=visual

AddJwtBearer OnAuthenticationFailed return custom error

本小妞迷上赌 提交于 2019-12-23 19:08:15
问题 I am using Openidict. I am trying to return custom message with custom status code, but I am unable to do it. My configuration in startup.cs : services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(o => { o.Authority = this.Configuration["Authentication:OpenIddict:Authority"]; o.Audience = "MyApp"; //Also in Auhorization.cs controller. o

mvc core 2.0, how to use an appSettings.json file via configuration

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 15:02:15
问题 Today I was trying out the new asp.net core 2.0 but ran into some trouble using a JSON configuration file that I wasnt to inject in IConfiguration configuration constructor property. In asp.net core 1.1 I would use this following code in StartUp: public static IConfigurationRoot Configuration; Public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appSettings.json", optional: false, reloadOnChange: true) Configuration

There was an error running the selected code generator: Could not load file or assembly Microsoft.EntityFrameworkCore, version = 2.0.1.0

强颜欢笑 提交于 2019-12-23 09:15:49
问题 When I was creating a Controller and a View by MVC Controller with views, using Entity Framework I got an error. The Error is: There was an error running the selected code generator: 'Could not load file or assembly Microsoft.EntityFrameworkCore, version = 2.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' the located assembly's manifest definition does not match the assembly reference Creating MVC Controller with views, using Entity Framework: How can I solve this problem? I use

Unexpected end of Stream, the content may have already been read by another component. Microsoft.AspNetCore.WebUtilities.MultipartReaderStream

微笑、不失礼 提交于 2019-12-23 08:49:27
问题 I get an exception when I try to read multi part content from the request saying the content may have already been read by another component. if (MultipartRequestHelper.IsMultipartContentType(Request.ContentType)) { // Used to accumulate all the form url encoded key value pairs in the // request. var formAccumulator = new KeyValueAccumulator(); var boundary = Request.GetMultipartBoundary(); var reader = new MultipartReader(boundary, HttpContext.Request.Body); var section = await reader