asp.net-web-api2

How to use Swagger as Welcome Page of IAppBuilder in WebAPI

依然范特西╮ 提交于 2019-11-28 21:05:30
问题 I try to use Swagger with Microsoft WebAPI 2. For the moment, I've the following call in a method. appBuilder .ConfigureOAuth() .UseWebApi(configuration) .UseWelcomePage(); If I want to use Swagger, I must use this url "https://localhost:44300/swagger" which one works very well. I want my home page redirects to the url of my swagger, perhaps as follows but this sample doesn't works. appBuilder ... .UseWelcomePage("/swagger"); Any idea ? 回答1: I got this working how I wanted by adding a route

AspNet Identity 2: Customize OAuth endpoint response

风流意气都作罢 提交于 2019-11-28 20:18:28
I successfully implemented my custom OAuthAuthorizationServerProvider . But when I log in and retrieve a token, my client doesn't have any idea of the user's roles, claims, etc. I currently added a webapi controller to return the list of the principal's claims, but I'm not really happy with that. When requesting a token, the current response looks like: { access_token: "qefelgrebjhzefilrgo4583535", token_type: "bearer", expires_in: 59 } Q> How can make it return something like the following snippet? { access_token: "qefelgrebjhzefilrgo4583535", token_type: "bearer", expires_in: 59, user: {

An assembly specified in the application dependencies manifest (…) was not found

拈花ヽ惹草 提交于 2019-11-28 19:53:39
问题 I upgraded Microsoft.AspNetCore from 2.0.3 to 2.0.5 and my WebAPI project, although running successfully locally, fails to start in production (IIS). Everything was fine in production until this upgrade. The error message produced in the log directory is as follows: Error: An assembly specified in the application dependencies manifest (MyProject.WebAPI.deps.json) was not found: package: 'Microsoft.AspNetCore.Mvc.Abstractions', version: '2.0.2' path: 'lib/netstandard2.0/Microsoft.AspNetCore

How to add custom methods to ASP.NET WebAPI controller?

杀马特。学长 韩版系。学妹 提交于 2019-11-28 19:17:33
In ASP.NET MVC WebAPI project by default we have created following controller public class ValuesController : ApiController { // GET api/values public IEnumerable<string> Get() { return new string[] { "value1", "value2" }; } // GET api/values/5 public string Get(int id) { return "value"; } // POST api/values public void Post([FromBody]string value) { } // PUT api/values/5 public void Put(int id, [FromBody]string value) { } // DELETE api/values/5 public void Delete(int id) { } } But is possible to add here any custom methods so they can support get/post as well? Thank you! You can use

How to change default Web API 2 to JSON formatter?

强颜欢笑 提交于 2019-11-28 18:21:39
I have a Web API project that returns some product data. It negotiates the return type correctly depending on the Accept header (JSON/XML) of the request. The problem is, if no Accept header is specified it returns XML, but I want it to return JSON by default http://website.com/MyPage?type=json // returns json http://website.com/MyPage?type=xml // returns xml http://website.com/MyPage // returns xml by default Here is my current code looks like: GlobalConfiguration.Configuration.Formatters.XmlFormatter.MediaTypeMappings.Add( new QueryStringMapping("type", "xml", new MediaTypeHeaderValue(

How do you consume extra parameters in OAuth2 Token request within .net WebApi2 application

▼魔方 西西 提交于 2019-11-28 18:12:01
I have an api specific project in a large .net MVC 5 web solution. I am utilizing the WebApi2 templates out of the box to authenticate a user through the api. Using individual accounts to authenticate, the request body required to get an access token is: grant_type=password&username={someuser}&password={somepassword} This works as expected. However, I need to add a 3rd dimension to the scaffolded method "GrantResourceOwnerCredentials". In addition to checking the username/password, i need to add a device id, which is meant to restrict access from a user account to a specific device. What's not

CORS on OWIN and accessing /token causes 'Access-Control-Allow-Origin' error

为君一笑 提交于 2019-11-28 17:55:47
I am having trouble with securing my Web API using owin middle ware. I have installed below package Install-Package Microsoft.Owin.Cors -Version 2.1.0 And below is ConfigureAuth.cs code. public void ConfigureAuth(IAppBuilder app) { //... app.UseOAuthBearerTokens(OAuthOptions); ///Install-Package Microsoft.Owin.Cors -Version 2.1.0 app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll); } I have hosted this WebApi project on a link , say , http://webaip.azurewebsites.net I am trying to access controller methods of above API from another site, say , http://mysite.azurewebsites.net With above code

Enable CORS for Web Api 2 and OWIN token authentication

巧了我就是萌 提交于 2019-11-28 16:47:39
问题 I have an ASP.NET MVC 5 webproject (localhost:81) that calls functions from my WebApi 2 project (localhost:82) using Knockoutjs, to make the communication between the two projects I enable CORS. Everything works so far until I tried to implement OWIN token authentication to the WebApi. To use the /token endpoint on the WebApi, I also need to enable CORS on the endpoint but after hours of trying and searching for solutions it is still now working and the api/token still results in:

ASP.NET Web Api 2 / EF6 first call initialization performance

廉价感情. 提交于 2019-11-28 16:47:04
问题 The first call to our API is always extremely slow. For example, below demonstrates the CPU usage and time it takes for the first call to complete: The first call can take up to 30 seconds and eats almost 100% CPU. Call 2 and 3 take 200ms (as they should). After recycling the application pool, it will do the same thing with the first call. I've read a bit about IIS "warm-up" and done the following, but nothing has changed: IIS 8 Application Initialization is installed: I have the following

Swagger UI Web Api documentation Present enums as strings?

心不动则不痛 提交于 2019-11-28 16:37:57
Is there a way to display all enums as their string value in swagger instead of their int value? I want to be able to submit POST actions and put enums according to their string value without having to look at the enum every time. I tried DescribeAllEnumsAsStrings but the server then receives strings instead of the enum value which is not what we're looking for. Has anyone solved this? Edit: public class Letter { [Required] public string Content {get; set;} [Required] [EnumDataType(typeof(Priority))] public Priority Priority {get; set;} } public class LettersController : ApiController {