asp.net-web-api2

return an image using ASP.NET Web API and display it?

不羁的心 提交于 2019-12-23 06:21:10
问题 web api action : byte[] bytes = System.IO.File .ReadAllBytes( HttpContext.Current.Server.MapPath("~/Images/orderedList1.png")); var result_ = new HttpResponseMessage(HttpStatusCode.OK); result_.Content = new ByteArrayContent(bytes); result_.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png"); return result_; Ajax call respond - data in console 回答1: You don't need to make an AJAX call to this action. Just put an <img> tag and point its src property to your Web API endpoint:

How to retrieve already cached data inside webapi controller method C#

允我心安 提交于 2019-12-23 05:30:35
问题 I have created a OutputCacheFilter attribute by inheriting ActionFilterAttribute to get the caching functionality for the controller method. This is my OutputCacheFilter class public class OutputCacheFilter : ActionFilterAttribute { // cache length in seconds private int _timespan; // true to enable cache private bool _cacheEnabled = false; // true if the cache depends on the caller user private readonly bool _dependsOnIdentity; // cache repository private static readonly ObjectCache

C# unit testing API 2 call

做~自己de王妃 提交于 2019-12-23 05:05:02
问题 I have a web api 2 web service get method. Inside I'm using HttpContext.Current.Request.UserHostAddress. When calling my controller method directly int he unit test this isn't filled in so is errors with null object. So I searched for how to fill this in and found the following which helped with that issue: Add IP address to HttpRequestMessage However, this needs a server name to send the request to. The problem is that when tests run the VSExpress will need to be running for this API web

How to add parameters to redirect_uri in WebApi Oauth Owin authentication process?

﹥>﹥吖頭↗ 提交于 2019-12-23 04:58:34
问题 I'm creating a webapi project with oauth bearer token authenthication and external login providers (google, twitter, facebook etc.). I started with the basic VS 2013 template and got everything to work fine! However, after a user successfully logs is, the owin infrastructure creates a redirect with the folllowing structure: http://some.url/#access_token=<the access token>&token_type=bearer&expires_in=1209600 In my server code I want to add an additional parameter to this redirect because in

Consuming Web API 2 OData endpoint requiring Windows Authentication with BreezeJS

我怕爱的太早我们不能终老 提交于 2019-12-23 04:45:22
问题 Has anyone have experience getting Breeze (or DataJS for that matter) to communicate with a Web API 2 OData endpoint which requires Windows Authentication and is hosted on a different server? I have successfully configured Web API to enable CORS and I am able to initiate a cross-domain request to the OData endpoint using jQuery: load: function () { $.ajax({ type: "GET", dataType: 'json', url: "http://services.company.com/odata/GeographicalRegions", xhrFields: { withCredentials: true },

Authorize Attribute Authentication with Postman in Web Api

折月煮酒 提交于 2019-12-23 03:47:51
问题 I am working with RESTful services and find Postman as one of the best plugin to GET, POST and test the API's. I find Basic Auth, No Auth, DIgest Auth, OAuth, AWS in postman. How do I test the Authorize Controller and methods. I am aware that Authorize attribute checks user.Identity.IsAuthenticated I am not sure on how to pass authorize in controller and methods with specific roles like below using Postman [Authorize(Roles = "Admin, Super User")] public ActionResult AdministratorsOnly() {

Web Api 2.2 - Code First Migration in Class Library Project

喜欢而已 提交于 2019-12-23 02:41:22
问题 I have two projects in myVS 2015 solution. Project A Web Api 2.2 Project Main Project where DBContext class and connection string (in web.config file) is defined Project B Class Library Project Project A added as a reference Models & Controller Defined Models inherits a class of Project A Created a DBContext class which inherits DBContext from Project A. public DbSet Planets { get; set; } My idea behind the above project structure is: To reduce the complexity when project grows larger To make

How to get date and time on ASP.Net Web API?

做~自己de王妃 提交于 2019-12-23 02:36:34
问题 I'm new on ASP.Net Web API and want to develop a sample to get date time. I developed two applications.In the first one i Have my API and run it throw Visual Studio and another one is a console application to test the first. On my API I have: public class DateTimeController : ApiController { public DateTime Get() { return DateTime.Now; } } and on my Console application I have this,but i do not know it's correct or not because it doesn't work: static void Main(string[] args) { string

Running ASP.NET Web Api 2 application without Visual Studio

穿精又带淫゛_ 提交于 2019-12-23 02:36:12
问题 I'm developing a asp web api 2 webservice for a private project. I created a webservice-project which includes all the folder (App_Data,App_Start,Controllers,...) and all my classes/functionallity. Now I would like to run it as a selfhosted windows service or from command line to test all the functionallity without running Visual Studio. All I found was a tutorial how to create a new command-line programm and create a new webservice (http://www.asp.net/web-api/overview/hosting-aspnet-web-api

modelbinder IsMultiPartContent always returning false. How to upload file with react

孤者浪人 提交于 2019-12-23 02:01:39
问题 I have the following react component import React, { Component } from 'react'; import { Row, Col } from 'antd'; import PageHeader from '../../components/utility/pageHeader'; import Box from '../../components/utility/box'; import LayoutWrapper from '../../components/utility/layoutWrapper.js'; import ContentHolder from '../../components/utility/contentHolder'; import basicStyle from '../../settings/basicStyle'; import IntlMessages from '../../components/utility/intlMessages'; import {