asp.net-web-api

WebApi2 in visual studio 2012

一笑奈何 提交于 2020-01-12 12:08:48
问题 How can I create a project that uses WebApi2 in visual studio 2012? Do I have to create with a blank project or do I have to create a MVC project? I don't want to install Visual Studio 2013 preview, please help. 回答1: You need to install ASP.NET and Web Tools 2013.1 for Visual Studio 2012 which adds the Web API 2 and MVC 5 templates 回答2: Create a MVC project, right-click to and select Create an MVC project Right click the project in solution explorer and select "Manage nuget packages" Select

OAuth on REST API for mobile app

你离开我真会死。 提交于 2020-01-12 08:27:29
问题 Ι'm working on the backend of a mobile app, building a RESTful API using ASP.NET MVC 4 Web Api. The app will run on iOS and Android. My users will be allowed to login only with their facebook account, and only when logged in, they will be able to use the whole functionality. I don't have much experience with mobile apps and that's more of a design question: Which of the two scenarios (or maybe a third one?) seems better design to you about who should be responsible for the facebook

Reading Form Data in ActionFilterAttribute

两盒软妹~` 提交于 2020-01-12 08:25:35
问题 I created an ActionFilterAttribute for my web api in order to authorize people. Getting accessToken by RequestUri is okay, however i want to send it in form data. While reading Request.Content in onActionExecuting method of ActionFilterAttribute, server always has an empty result. How can i solve this problem? The code is as like as below: public class RequireAuthorization : ActionFilterAttribute { public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext

JsonSerializationException on lazy loaded nHibernate object in WebApi when called from Angularjs service

放肆的年华 提交于 2020-01-12 08:24:48
问题 I am calling a WebApi controller Get method from an Angularjs service. The angular service: app.service('MyService', ['$http', function ($http) { var getMyObjects = function () { var myObjects; var promise = $http.get('/api/objects/').success(function (data) { myObjects = data; }).error(function (data, status, headers, config) { }); return promise; }; return { myObjects: myObjects }; }]); The WebApi Get method: public class ObjectsController : ApiController { public IEnumerable<MyObject> Get(

Binding abstract action parameters in WebAPI

痞子三分冷 提交于 2020-01-12 07:28:08
问题 I'm in a situation where I need to bind an incoming HTTP POST request with data in the body, to a concrete type depending on a ProductType denominator in the data. Here is my Web API 2 action method: [HttpPost, Route] public HttpResponseMessage New(ProductBase product) { // Access concrete product class... if (product is ConcreteProduct) // Do something else if (product is OtherConcreteProduct) // Do something else } I was first thinking of using a custom model binder, but it seems like it

Credentials flag is 'true', but the 'Access-Control-Allow-Credentials

大城市里の小女人 提交于 2020-01-12 07:23:55
问题 I am trying to connect to a ASP.NET Web-API Web Service from an AngularJS page and I am getting the following Credentials flag is 'true', but the 'Access-Control-Allow-Credentials' header is ''. It must be 'true' to allow credentials. Origin 'http://localhost:221' is therefore not allowed access. var cors = new EnableCorsAttribute("http://localhost:221", "*","GET,PUT,POST,DELETE"); config.EnableCors(cors); Using this AngularJS $http({ method: 'GET', url: 'http://localhost:1980/api/investors

Cannot create a TypeConverter for a generic type

馋奶兔 提交于 2020-01-12 06:55:31
问题 I'd like to create a TypeConverter for a generic class, like this: [TypeConverter(typeof(WrapperConverter<T>))] public class Wrapper<T> { public T Value { // get & set } // other methods } public class WrapperConverter<T> : TypeConverter<T> { // only support To and From strings public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == typeof(string)) { return true; } return base.CanConvertFrom(context, sourceType); } public override bool

“Access is denied” on build server when deploying Web API project with XML documentation

梦想的初衷 提交于 2020-01-12 06:51:09
问题 In order to generate XML documentation using Web API Help Pages for my Web API project, I had to check the "XML documentation file" option under the "Builds" section of my project's properties. This correctly generates the documentation when I build locally. However, when I check in, I get the following error on the build server: CSC: Error generating XML documentation file 'c:\Builds\3...\Sources\CurrentVersion...\ProjectName\App_Data\XmlDocument.xml' ('Access is denied. ') I'm not sure why

How do I set a response cookie on HttpReponseMessage?

…衆ロ難τιáo~ 提交于 2020-01-12 06:31:25
问题 I would like to create a demo login service in web api and need to set a cookie on the response. How do I do that? Or are there any better way to do authorization? 回答1: Add a reference to System.Net.Http.Formatting.dll and use the AddCookies extension method defined in the HttpResponseHeadersExtensions class. Here is a blog post describing this approach, and the MSDN topic. If that assembly isn't an option for you, here's my older answer from before this was an option: Older answer follows I

Integration Test Web Api With [Authorize]

。_饼干妹妹 提交于 2020-01-12 05:45:08
问题 So I've found bits and pieces that have enlightened me some on the [Authorize] tag, but nothing that solves my problem. My scenario is that I have Web Api methods that I want to hit with integration tests using RestSharp. However RestSharp is getting my login page, instead of the results of the call. [Authorize] public Item GetItem([FromBody] int id) { return service.GetItem(id); } The product uses a custom login system, and what I would REALLY like would be a way to disable the [Authorize]