asp.net-web-api

Make Web API authentication return 401 instead of redirect to login page

耗尽温柔 提交于 2019-12-30 05:50:53
问题 I have Web API with OWIN Authentication in Web MVC. I'm using <authentication> in Web.Config for my Web MVC so it's redirecting to login page. <authentication mode="Forms"> <forms name="WEB.AUTH" loginUrl="~/login" domain="" protection="All" timeout="43200" path="/" requireSSL="false" slidingExpiration="true" /> </authentication> I'm using [System.Web.Http.Authorize] attribute to authorize my Web API. But somehow, the API redirecting to login page same like my MVC app because of above

ASP.NET Web API - No 'MediaTypeFormatter' is available to read an object of type 'Int32'

吃可爱长大的小学妹 提交于 2019-12-30 05:46:31
问题 I'm not entirely sure whats happened here. I may have messed things up somewhere, but I don't know what. My API controller method looks like this: public HttpResponseMessage<string> Put(int id) I've tried a string as well with the same error. Any ideas? Thanks. Edit: To be clear - the id is the route parameter. The body of the request is JSON. If I remove the route parameter,the method functions as normal. 回答1: Please read following blog post: ASP.NET Web API and Simple Value Parameters from

Manually decode OAuth bearer token in c#

你离开我真会死。 提交于 2019-12-30 04:22:06
问题 In my Web Api 2.2 OWIN based application I have a situation where I manually need to decode the bearer token but I don't know how to do this. This is my startup.cs public class Startup { public static OAuthAuthorizationServerOptions OAuthServerOptions { get; private set; } public static UnityContainer IoC; public void Configuration(IAppBuilder app) { //Set Auth configuration ConfigureOAuth(app); ....and other stuff } public void ConfigureOAuth(IAppBuilder app) { OAuthServerOptions = new

Self-hosting WebAPI application referencing controller from different assembly

你说的曾经没有我的故事 提交于 2019-12-30 04:03:10
问题 I came across this gem, which seemed to be close to what I wanted. However, I want to use the already-written controllers from a referenced assembly. My first crack was to reference the assembly, set up the routing rules the same as the original webAPI project and go, but I get 400s every time I try to call the self-hosted service. I've picked through the innards of the request with Fiddler, and aside from the address differences, the requests against the webAPI project and the self-hosted

owin cors or web api cors

送分小仙女□ 提交于 2019-12-30 03:55:08
问题 there are 100s of question on CORS on web-api, and on how to enable CORS, there is a different answer each one provides. I am so confused and dont know which answer is correct. And the problem is none of the answers actually explains it point wise, what each line of code does, so that I can understand and solve my problem rather than copy-pasting the code. anyways, the question is: I am using asp.net web api 2 using owin. And i need to enable CORS. how do I do it? There is cors settings for

Asp.net web api exception only after deploying at IIS : A route named 'HelpPage_Default' is already in the route collection

≡放荡痞女 提交于 2019-12-30 03:40:21
问题 I've read this question and tried the solutions mentioned there but I'm getting this exception only after i published the application to IIS of a remote server. In my local computer's IIS the application is working fine. I've no clue what is causing this exception at that server: Server Error in '/' Application. A route named 'HelpPage_Default' is already in the route collection. Route names must be unique. Parameter name: name Description: An unhandled exception occurred during the execution

How to return html page from WebApi action?

喜欢而已 提交于 2019-12-30 02:36:07
问题 I'm looking for a WebApi example where the default route will return a given html page to the caller. I've got the route and action set up as follows. I just want to send him the index.html page, not redirect, because he's in the right place. http://localhost/Site // load index.html // WebApiConfig.cs config.Routes.MapHttpRoute( name: "Root", routeTemplate: "", defaults: new { controller = "Request", action = "Index" } ); // RequestControlller.cs [HttpGet] [ActionName("Index")] public

What is the future of ASP.NET MVC framework after releasing the asp.net Web API

穿精又带淫゛_ 提交于 2019-12-30 00:40:09
问题 I have been using asp.net MVC for around 1.5 years, am enjoying its capabilities, and have deployed many successful web applications, but I'm currently reading about the asp.net Web API technology. And, I find the following: I can implement any functionality that I used to implement using MVC; using the new Web API and in a more lightweight approach. It is easier to develop web services using the Web API comparing the asp.net MVC. So, will the asp.net Web API take over asp.net MVC in the

JSON.Net JsonConverter for DbGeography

三世轮回 提交于 2019-12-30 00:38:25
问题 Long long struggles with this... Basically I have a model-first EF5 object with a DbGeography property. I would like to apply a JsonConverter that let's it roundtrip as simple latitude/longitude values. I'm using WebAPI. Looking for JSON output and input like so: { "location": { "geopoint": { "latitude":40.770712, "longitude":-73.962011 } } } Here is my class definition and JsonConverter: [MetadataType(typeof(QueryLocationMetadata))] partial class Location { } public class

How to link exceptions to requests in Application Insights on Azure?

。_饼干妹妹 提交于 2019-12-29 17:47:30
问题 We are using Owin on Azure for a REST service, and have to report to Application Insights directly. We want to log exceptions and requests. Right now we have this: using AppFunc = Func<IDictionary<string, object>, Task>; public class InsightsReportMiddleware { readonly AppFunc next; readonly TelemetryClient telemetryClient; public InsightsReportMiddleware(AppFunc next, TelemetryClient telemetryClient) { if (next == null) { throw new ArgumentNullException("next"); } this.telemetryClient =