asp.net-web-api

How to call a Repository on application startup using DI while creating HttpContext

一曲冷凌霜 提交于 2020-06-29 05:16:21
问题 I need to make a database call when the application starts up to set up some cache. I have custom DbContext class which has a HttpContext within to hold the current sql connection as follows: public sealed class DataContext : IDataContext { IDbConnection connection = null; IDbTransaction transaction = null; Guid id = Guid.Empty; List<String> ConnectionList; public DataContext(string Con = RuntimeDTO.DEFAULTDB) { HttpContext context = AppHttpContext.Current; if (context.Items[Con] == null) {

SSO for .net core 3.1 web api

自作多情 提交于 2020-06-29 03:59:07
问题 We would like to achieve SSO( Google, Microsoft, Twitter, Facebook ) for a .net core 3.1 web api (console api controllers) application. I have gone through few links that achieves this with the help of MVC or angular front end and IdentityServer4 . Our application is purely an web api. Can some one guide me with sample code or link to achieve this? How does SignInWithGoogle/FB/Twitter/Microsoft button and its click will be handled? 来源: https://stackoverflow.com/questions/62173069/sso-for-net

Ninject with Web Api, SignalR, MVC and OWIN

拟墨画扇 提交于 2020-06-27 11:28:29
问题 I am using a Ninject DI in my web application with a bunch of technoligies from Asp.Net stack (MVC, Web Api 2, SignalR). I have managed to make DI work for all technologies in use with the following approach: public static class NinjectWebCommon { private static readonly Bootstrapper bootstrapper = new Bootstrapper(); /// <summary> /// Starts the application /// </summary> public static void Start() { DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule)); DynamicModuleUtility

Hanging TuesPechkin after initial conversion

妖精的绣舞 提交于 2020-06-27 08:00:50
问题 I am attempting to create a Web API that can convert a styled HTML file into a PDF. I am using TuesPechkin and have installed my application into IIS (as a 32-bit app: I have modified the application pool to run in 32bit mode). IIS 8.5 is running on Windows Server 2012 R2. PDFConversion class in C#: using System.Drawing.Printing; using System.IO; using TuesPechkin; namespace PDFApi { public class PDFcreator { public void convert(string path, string uri) { IConverter converter = new

Hanging TuesPechkin after initial conversion

萝らか妹 提交于 2020-06-27 07:59:31
问题 I am attempting to create a Web API that can convert a styled HTML file into a PDF. I am using TuesPechkin and have installed my application into IIS (as a 32-bit app: I have modified the application pool to run in 32bit mode). IIS 8.5 is running on Windows Server 2012 R2. PDFConversion class in C#: using System.Drawing.Printing; using System.IO; using TuesPechkin; namespace PDFApi { public class PDFcreator { public void convert(string path, string uri) { IConverter converter = new

How to address entity that uses composite identity key in OData Url?

流过昼夜 提交于 2020-06-27 07:08:21
问题 I have an entity OrderItem that has OrderId and ProductId integer fields and these two fields form the identity key/primary key for this table. I would like to use OData/Web API to expose such entities through a service and to be able to select OrderItem instances by they composite ID . What should be the format of the URL ? Are there any best practices for handling such scenarios? 回答1: Composite keys in the URL use syntax like this: ~/OrderItems(OrderId=1234,ProductId=1234) The "grammar" is

How to get only Odata.Count without value

自作多情 提交于 2020-06-27 06:50:12
问题 Is there any way I can get only count of the data in response payload without any value array? I am using ODataV4.0 with Webapi 2.2. Currently it returns all the values and count when I query something like: http://odata/People?$count=true I just need something like "@odata.count":1, "value":[] or without "value" . Is the only way to have function for this job? 回答1: Set the $top to zero and $count to true. For example: http://services.odata.org/V4/Northwind/Northwind.svc/Customers?$count=true

Saving a base64 string as an image into a folder on server using C# and Web Api

◇◆丶佛笑我妖孽 提交于 2020-06-24 12:22:28
问题 I am posting a Base64 string via Ajax to my Web Api controller. Code below Code for converting string to Image public static Image Base64ToImage(string base64String) { // Convert base 64 string to byte[] byte[] imageBytes = Convert.FromBase64String(base64String); // Convert byte[] to Image using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length)) { Image image = Image.FromStream(ms, true); return image; } } Controller Code public bool SaveImage(string ImgStr, string ImgName) { Image

How to Use MVC Controller and WebAPI Controller in same project

泪湿孤枕 提交于 2020-06-24 07:13:25
问题 I am trying to use an MVC Controller and a Web API controller in the same project, but I get 404 errors for the Web API. I started the project as an MVC project in VS 2015, but then added the Web API controller, and with the default code it is giving a 404 error. What could be the possible solution? I have tried some solutions on Stack Overflow, but they didn't work. One I tried is the accepted answer from this question: All ASP.NET Web API controllers return 404 Global.asax: protected void

composite key resource REST service

心不动则不痛 提交于 2020-06-24 07:06:12
问题 I've come across a problem at work where I can't find information on the usual standard or practice for performing CRUD operations in a RESTful web service against a resource whose primary key is a composite of other resource ids. We are using MVC WebApi to create the controllers. For example, we have three tables: Product : PK=ProductId Part : PK=PartId ProductPartAssoc : PK=(ProductId, PartId) A product can have many parts and a part can be a component of many products. The association