asp.net-web-api2

MVC-Web API: 405 method not allowed

[亡魂溺海] 提交于 2019-11-27 01:52:50
So, I am stuck in a strange behavior, that is, I am able to send(or POST) data using Postman (plugin of chrome) or using RESTClient(extension of Firefox) , but not able to send it from my html file which lies outside the project. It shows following error when i open the html in chrome: OPTIONS http://localhost:1176/api/user/ 405 (Method Not Allowed) XMLHttpRequest cannot load http://localhost:1176/api/user/. Invalid HTTP status code 405 I am not able to make out why is this happening. Following are the details, you might need to help me solve my error: UserController.cs: using System; using

OPTIONS 405 (Method Not Allowed) web api 2

馋奶兔 提交于 2019-11-27 01:52:37
问题 I have created a web api 2 and I'm trying to do a cross domain request to it but I'm getting the following error: OPTIONS http://www.example.com/api/save 405 (Method Not Allowed) I have had a look around and most resolutions for this problem are saying that I need to install CORs from NuGet and enable it so I have installed the package and marked my controller with [EnableCors("*", "*", "*")] But this still hasn't resolved the problem. My ApiController only has the following Save method in:

Where can I find a NuGet package for upgrading to System.Web.Http v5.0.0.0?

落花浮王杯 提交于 2019-11-27 00:32:04
问题 Just upgraded an ASP.NET MVC4 project to use Unity.WebApi version 5.0.0.0 and it requires System.Web.Http v 5.0.0.0 as per the following error: Assembly 'Unity.WebApi, Version=5.1.0.0, Culture=neutral, PublicKeyToken=43da31bc42a85347' uses 'System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' I am currently referencing System

JsonConverter with Interface

限于喜欢 提交于 2019-11-26 23:02:45
I have an object which comes from the client and get deserialized from the Web Api 2 automatically. Now I have a problem with one property of my model. This property "CurrentField" is of Type IField and there are 2 different Implementations of this interface. This is my model (just a dummy) public class MyTest { public IField CurrentField {get;set;} } public interface IField{ string Name {get;set;} } public Field1 : IField{ public string Name {get;set;} public int MyValue {get;set;} } public Field2 : IField{ public string Name {get;set;} public string MyStringValue {get;set;} } I tried to

How to implement oauth2 server in ASP.NET MVC 5 and WEB API 2 [closed]

北慕城南 提交于 2019-11-26 21:13:05
First I'll sketch my project: For my internship I need to add functionality to an existing system. A 3rd party client must be able to access data from AX Webservices once he is authorised by the user via OAuth2. I understand that I need to make a 'proxy web service' whereto the client can make its calls and that calls the AX services but I am a bit unsure about the OAuth2 part. Most tutorials and guides are about using ASP.NET's Identity for Facebook or Google-logins. I do not need that, I need to use existing credentials so I need to make my own OAuth2 service. I find it hard to find

Asp.Net WebApi2 Enable CORS not working with AspNet.WebApi.Cors 5.2.3

爱⌒轻易说出口 提交于 2019-11-26 19:34:25
I tried to follow the steps at http://enable-cors.org/server_aspnet.html to have my RESTful API (implemented with ASP.NET WebAPI2) work with cross origin requests (CORS Enabled). It's not working unless I modify the web.config. I installed WebApi Cors dependency: install-package Microsoft.AspNet.WebApi.Cors -ProjectName MyProject.Web.Api Then in my App_Start I've got the class WebApiConfig as follows: public static class WebApiConfig { public static void Register(HttpConfiguration config) { var corsAttr = new EnableCorsAttribute("*", "*", "*"); config.EnableCors(corsAttr); var

How to configure Web Api 2 to look for Controllers in a separate project? (just like I used to do in Web Api)

女生的网名这么多〃 提交于 2019-11-26 19:21:53
问题 I used to place my controllers into a separate Class Library project in Mvc Web Api. I used to add the following line in my web api project's global.asax to look for controllers in the separate project: ControllerBuilder.Current.DefaultNamespaces.Add("MyClassLibraryProject.Controllers"); I never had to do any other configuration, except for adding the above line. This has always worked fine for me. However I am unable to use the above method to do the same in WebApi2. It just doesn't work.

Return more info to the client using OAuth Bearer Tokens Generation and Owin in WebApi

ぐ巨炮叔叔 提交于 2019-11-26 18:49:36
问题 I have created a WebApi and a Cordova application. I am using HTTP requests to communicate between the Cordova application and the WebAPI. In the WebAPI, I've implemented OAuth Bearer Token Generation. public void ConfigureOAuth(IAppBuilder app) { var oAuthServerOptions = new OAuthAuthorizationServerOptions { AllowInsecureHttp = true, TokenEndpointPath = new PathString("/token"), AccessTokenExpireTimeSpan = TimeSpan.FromDays(1), Provider = new SimpleAuthorizationServerProvider(new UserService

Newtonsoft Json serialize a class where one of the properties is JSON [duplicate]

雨燕双飞 提交于 2019-11-26 18:35:49
问题 This question already has an answer here: Serialize object to JSON that already contains one JSON property 2 answers I'm using Newtonsoft Json serialization (with Web API 2). One of the public properties on my class is a String that holds JSON data. I'd like to serialize my class, and include this public property, but I don't want the serializer to process/modify the contents of this string. Is there any way I can include this property, but not mess with its contents? 回答1: You could make a

OData V4 modify $filter on server side

六眼飞鱼酱① 提交于 2019-11-26 18:16:39
问题 I would like to be able to modify the filter inside the controller and then return the data based on the altered filter. So for I have an ODataQueryOptions parameter on the server side that I can use to look at the FilterQueryOption. Let's assume the filter is something like this "$filter=ID eq -1" but on the server side if I see "-1" for an ID this tells me that the user wants to select all records. I tried to change the "$filter=ID eq -1" to "$filter=ID ne -1" which would give me all by