asp.net-web-api

A simple ASP .NET MVC API controller using roles

三世轮回 提交于 2021-02-07 11:14:44
问题 I wrote a web application using ASP .NET MVC and authorization system by default. I configured IdentityRole and input through external providers. Using the current database I have created my data context. Now I want to write a Xamarin.Android app and connect to my database, I want a simple API. But the feature that you want to access this API was only available to user with a certain role. The API is really very simple and therefore do not want to add to the draft WCF or WebAPI project. How

A simple ASP .NET MVC API controller using roles

老子叫甜甜 提交于 2021-02-07 11:13:59
问题 I wrote a web application using ASP .NET MVC and authorization system by default. I configured IdentityRole and input through external providers. Using the current database I have created my data context. Now I want to write a Xamarin.Android app and connect to my database, I want a simple API. But the feature that you want to access this API was only available to user with a certain role. The API is really very simple and therefore do not want to add to the draft WCF or WebAPI project. How

JSON object creation PushStreamContent

馋奶兔 提交于 2021-02-07 09:45:46
问题 I have asp.net web api and has a HTTPResponseMessage and the api method name GetPersonDataStream , which actually stream each person object as a json. So when I see the result the actual Data has been constructed like two seperate object's with no comma in between the two objects are it isn't constructed as I required. Actual streamed data : {"Name":"Ram","Age":30}{"Name":"Sam","Age":32} . But I want this to streamed as a proper JSON as: {"response": [ {"Name":"Ram","Age":30}, {"Name":"Sam",

JSON object creation PushStreamContent

旧城冷巷雨未停 提交于 2021-02-07 09:45:36
问题 I have asp.net web api and has a HTTPResponseMessage and the api method name GetPersonDataStream , which actually stream each person object as a json. So when I see the result the actual Data has been constructed like two seperate object's with no comma in between the two objects are it isn't constructed as I required. Actual streamed data : {"Name":"Ram","Age":30}{"Name":"Sam","Age":32} . But I want this to streamed as a proper JSON as: {"response": [ {"Name":"Ram","Age":30}, {"Name":"Sam",

Add more values to the bearer token json

风流意气都作罢 提交于 2021-02-07 09:30:42
问题 I want to return the user name after they logged in successfully to display on the upper right corner on my web app. I want to send it with the json that bearer the token returns. To generate the token authentication I'm using ASP.NET web API and Owin middlehawe. { "access_token": "blah", "token_type": "bearer", "expires_in": 599 } I want the return to be like this { "access_token": "blah", "token_type": "bearer", "expires_in": 599, "displayusername":"Hi Mundo" } I have tried claims but those

Add more values to the bearer token json

这一生的挚爱 提交于 2021-02-07 09:29:41
问题 I want to return the user name after they logged in successfully to display on the upper right corner on my web app. I want to send it with the json that bearer the token returns. To generate the token authentication I'm using ASP.NET web API and Owin middlehawe. { "access_token": "blah", "token_type": "bearer", "expires_in": 599 } I want the return to be like this { "access_token": "blah", "token_type": "bearer", "expires_in": 599, "displayusername":"Hi Mundo" } I have tried claims but those

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

Swagger .netcore 3.1 in Web Api, set the date time format with swagger UI

白昼怎懂夜的黑 提交于 2021-02-07 09:12:31
问题 I am wondering if anyone can help me, I am trying to change the date format in swagger UI from 2020-03-07T14:49:48.549Z to 07-03-2020T14:49 I am trying to remove the seconds and put the date format into " dd/MM/yyyy HH:mm ", now I have tried services.AddControllers() .AddNewtonsoftJson(options => { var dateConverter = new Newtonsoft.Json.Converters.IsoDateTimeConverter { DateTimeFormat = "dd'/'MM'/'yyyy HH:mm:ss" }; options.SerializerSettings.Converters.Add(dateConverter); options

How To Add Custom ModelValidatorProviders To Web API Project?

▼魔方 西西 提交于 2021-02-07 07:39:28
问题 I'm moving some MVC code to Web API and I need to update my custom ModelValidatorProviders. It seems as though my validators can stay much the same only they should inherit the System.Web.Http.Validation namespace. What I can't figure out is how to add the provider to Web API. When using MVC I can just add the following to my global.asax: ModelValidatorProviders.Providers.Add(new CustomModelValidatorProvider()); How do I use the custom provider with Web API? 回答1: This page Configuring ASP.NET

Send ASP.NET MVC HttpContext to Web Api HttpContext

霸气de小男生 提交于 2021-02-07 04:31:25
问题 I'm trying to upload a file and I'd like to pass the current MVC HttpContext.Current.Request.Files to a Web API. I tried to pass the HttpFileCollectionBase as parameter to pass it to the API but it's always null. Controller public object UploadAttachment(string param1, int param2, HttpFileCollectionBase files) { string _url = _restUrl + param1+ "/Folders/" + param2+ "/UploadAttachment"; HttpResponseMessage _response = SendJsonRequest(_url, HttpMethod.Post, files); var ret =