asp.net-web-api2

Shorten access token returned by OWIN in ASP.NET WebAPI 2

怎甘沉沦 提交于 2021-02-07 09:28:29
问题 We've developed a REST API using ASP.NET WebAPI 2 & secured it using ASP.NET Identity. The client required that their token be set to a long expiration time, as they store the access token in their database. During testing, they requested that we reduce the length of the token, as their database can only handle strings up to 250 characters. Our implementation is pretty "vanilla". Below are the options we're currently setting for the bearer token: OAuthOptions = new

Long running method in controller action - MVC [duplicate]

非 Y 不嫁゛ 提交于 2021-02-07 09:15:29
问题 This question already has answers here : Long running task in WebAPI (5 answers) Closed 6 years ago . I have a method similar to the following in WebAPI - MVC public IActionResult Post(Model model) { ALongRunningMethod(); return Ok(); } I have two options. Wait for the method to complete. But, what if its too long ? Doesn't the API timeout ? Run that in a separate thread using Tasks but return Ok (200 HTTP Code) immediately ? What if some exception occur in that long running method ? Totally

Pass decimal as value in WebAPI 2 URL

时间秒杀一切 提交于 2021-02-07 04:57:17
问题 I am creating a Web Api (v2.0) Method that needs to take in a decimal value as its parameter. I am getting a 404 not found error if I use the following URL: http://localhost:4627/api/Product/Eligibility/10.5 But it works if I use the following URL against an Int parameter: Http://localhost:4627/api/Product/Eligibility/10 These are the two corresponding Methods in the api: // GET api/Product/Eligibility/10.0 [Route("api/Product/Eligibility/{amount:decimal}")] public decimal GetEligibiilty

Error loading System.IdentityModel.Tokens.Jwt dll in WebAPI2 project

别说谁变了你拦得住时间么 提交于 2021-02-06 10:01:47
问题 I am getting the below error in WebApi2 project: Could not load file or assembly 'System.IdentityModel.Tokens.Jwt, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) I have these set of related NuGet packages installed, along with a bunch of others: "Microsoft.IdentityModel.Protocol.Extensions" version="1.0.2.206221351"

API end point returning “Authorization has been denied for this request.” when sending bearer token

让人想犯罪 __ 提交于 2021-02-05 23:17:13
问题 I've followed a tutorial to protect a Web API with OAuth in C#. I'm doing some tests and so far I've been able to get the access token successfully from /token . I'm using a Chrome extension called "Advanced REST Client" to test it. {"access_token":"...","token_type":"bearer","expires_in":86399} This is what I get back from /token . Everything looks good. My next request is to my test API Controller: namespace API.Controllers { [Authorize] [RoutePrefix("api/Social")] public class

API end point returning “Authorization has been denied for this request.” when sending bearer token

妖精的绣舞 提交于 2021-02-05 22:51:26
问题 I've followed a tutorial to protect a Web API with OAuth in C#. I'm doing some tests and so far I've been able to get the access token successfully from /token . I'm using a Chrome extension called "Advanced REST Client" to test it. {"access_token":"...","token_type":"bearer","expires_in":86399} This is what I get back from /token . Everything looks good. My next request is to my test API Controller: namespace API.Controllers { [Authorize] [RoutePrefix("api/Social")] public class

How to wait for the result while controller is making parallel call

微笑、不失礼 提交于 2021-02-05 12:26:02
问题 I am trying to find account details from DB (GetAccountDetailAsync) for an array of accounts and would like to run in parallel to make it faster. [HttpPost] public async Task<IHttpActionResult> GetAccountsAsync(IEnumerable<int> accountIds) { var resultAccounts = new List<AccountDetail>(); var task = Task.Run(() => { Parallel.ForEach(accountIds, new ParallelOptions { MaxDegreeOfParallelism = 5 }, async accountId => { var response = await GetAccountDetailAsync(accountId).ConfigureAwait(false);

Forcing certain code to always run on the same thread

时间秒杀一切 提交于 2021-02-05 08:21:06
问题 We have an old 3rd party system (let's call it Junksoft® 95) that we interface with via PowerShell (it exposes a COM object) and I'm in the process of wrapping it in a REST API (ASP.NET Framework 4.8 and WebAPI 2). I use the System.Management.Automation nuget package to create a PowerShell in which I instantiate Junksoft's COM API as a dynamic object that I then use: //I'm omitting some exception handling and maintenance code for brevity powerShell = System.Management.Automation.PowerShell

web api in subdirectory application

旧街凉风 提交于 2021-01-29 07:56:16
问题 I am creating a hub site with links to various apps, which are all stored in subdirectories under the main hub site. One of these apps has a web api, which works fine when debugging on localhost. However, when I publish to the subdirectory, I get a 404 error when trying to hit the api. Based on other questions, I made sure to "create application" in IIS for the subdirectory. This is my first web api attempt and I don't know what else to try, or even what other info I should give to clarify

Kofax TotalAgility Send a PDF Document to Jobs Queue (KTA)

余生长醉 提交于 2021-01-28 16:42:49
问题 I'm at a loss with the KTA SDK. My intention is to pass a scanned document in PDF format with a few headers to KTA's jobs queue. As I'm still going through the documentation, my best guess right now is to use the Document class as a DTO then I need to call a method to pass that Document as a parameter: ... [HttpPost] public HttpResponseMessage Upload() { var httpRequest = System.Web.HttpContext.Current.Request; var DocType = httpRequest.Headers["X-DocType"]; var Pages = httpRequest.Headers["X