asp.net-core-webapi

How can I connect to a database in ASP.NET Core without Entity Framework?

若如初见. 提交于 2020-03-16 07:11:11
问题 How can I connect to a database from ASP.NET Core and Angular without Entity Framework? "ConnectionStrings": { "DefaultParkingConnection": "Server=DESKTOP-CD0M0C3\\SQLEXPRESS;Database=ParkingSystem2;Trusted_Connection=True;MultipleActiveResultSets=true;User ID=sa;Password=P@ssw0rd" }, How can I get connection string in Web API controller? string constr = ConfigurationManager.ConnectionStrings["DefaultParkingConnection"].ConnectionString; 回答1: ASP.Net Core works different than ASP.Net, so you

How can I connect to a database in ASP.NET Core without Entity Framework?

给你一囗甜甜゛ 提交于 2020-03-16 07:09:10
问题 How can I connect to a database from ASP.NET Core and Angular without Entity Framework? "ConnectionStrings": { "DefaultParkingConnection": "Server=DESKTOP-CD0M0C3\\SQLEXPRESS;Database=ParkingSystem2;Trusted_Connection=True;MultipleActiveResultSets=true;User ID=sa;Password=P@ssw0rd" }, How can I get connection string in Web API controller? string constr = ConfigurationManager.ConnectionStrings["DefaultParkingConnection"].ConnectionString; 回答1: ASP.Net Core works different than ASP.Net, so you

response: 413 Request Entity Too Large

不羁岁月 提交于 2020-03-05 04:44:11
问题 When POSTing a request which can contain one or more files (as base64 string) I get this error response: ERROR 2018-11-22 09:54:18,244 [13 ] Mvc.ExceptionHandling.AbpExceptionFilter - The remote server returned an unexpected response: (413) Request Entity Too Large. System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (413) Request Entity Too Large. at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result) at System.ServiceModel.Channels

Conventional Routing in ASP.NET Core API

大憨熊 提交于 2020-02-28 05:50:19
问题 Problem: I'm creating an API Application with NET Core 3.1. I'd like to avoid to set route attribute over every ApiControllers and Actions. I tryed a lot of combinations over UseEndpoints to set a conventional route, but i'm failing. With some configuration I can't get the Api working, with some others I get this exception during startup: InvalidOperationException: Action 'ApiIsWorking' does not have an attribute route. Action methods on controllers annotated with ApiControllerAttribute must

Create 3 Tier Architecture In DotNet Core 2.2 Web API C#

为君一笑 提交于 2020-02-25 07:00:49
问题 I am working on Web API Core 2.2 and need to design 3 tier architecture. How can I do it. My Project Structure as below In Web API Project.. public void ConfigureServices(IServiceCollection services) { services.AddDbContext<HrmsDbContext>(opt => opt.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); } In DAL (Library project, I have made my DBContext and provided connectionstring like below. Is there any better so that I had not provide connectionstring at two places? and

Create 3 Tier Architecture In DotNet Core 2.2 Web API C#

风格不统一 提交于 2020-02-25 06:59:14
问题 I am working on Web API Core 2.2 and need to design 3 tier architecture. How can I do it. My Project Structure as below In Web API Project.. public void ConfigureServices(IServiceCollection services) { services.AddDbContext<HrmsDbContext>(opt => opt.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); } In DAL (Library project, I have made my DBContext and provided connectionstring like below. Is there any better so that I had not provide connectionstring at two places? and

Getting OData Count in ASP.NET Core WebAPI

纵饮孤独 提交于 2020-02-24 06:48:50
问题 Using the sample code from Hassan Habib's Supercharging ASP.NET Core API with OData blog post, I am able to get the record count using an OData query of $count=true : What needs to be configured to get the response object to be wrapped in an OData context so that the @odata.count property will show? In my own ASP.NET Core web API project, I cannot get the simple $count parameter to work and I have no idea why. With Hassan's sample code, the response JSON is wrapped in an OData context and the

ASP.Net Core API always returns 401 unauthorized whenever I send a request with Bearer token included

为君一笑 提交于 2020-02-24 03:07:37
问题 I have an ASP .NET Core web api and I generate a JWT token for authorization purposes but whenever I make a request with Postman with Bearer token header I get 401 Unauthorized. Same when I try from my front-end that's consuming the API. When I remove Authorize everything works fine Tried changing Authorize in my header to //[Authorize(AuthenticationSchemes = "Bearer")] also went to jwt.io to ensure the JWT Token is valid which it is. //function where I generate JWT public User

ASP.Net Core API always returns 401 unauthorized whenever I send a request with Bearer token included

牧云@^-^@ 提交于 2020-02-24 03:05:51
问题 I have an ASP .NET Core web api and I generate a JWT token for authorization purposes but whenever I make a request with Postman with Bearer token header I get 401 Unauthorized. Same when I try from my front-end that's consuming the API. When I remove Authorize everything works fine Tried changing Authorize in my header to //[Authorize(AuthenticationSchemes = "Bearer")] also went to jwt.io to ensure the JWT Token is valid which it is. //function where I generate JWT public User

Anti forgery with token API and angular

て烟熏妆下的殇ゞ 提交于 2020-02-16 08:23:13
问题 I am working on Angular 6 application with SSO login and .net core web API. The code hits the back end on /token url first time which is a post operation. How do I do the anti forgery in this scenario. Please explain the flow of token transfer 回答1: I'm not sure if that's what you're looking for, but I'll try to explain how I achieved it in a similar case. First of all Angular has built in helpers for XSRF handling: https://angular.io/guide/security#http https://angular.io/api/common/http