asp.net-web-api

How to handle authorization with Breeze JS?

旧时模样 提交于 2020-01-11 09:43:08
问题 Currently my app looks at router parameter and logged in user (Principal.Identity) to authorize access to certain resources (e.g: Add student to your class [identity + class id]). However, If I'm not wrong, breeze js support just one bulk save. It seems to be that I will have to open each and every data and run through the validation/authorization. That is fine, but what I may lose is nice separation of cross cutting concern out side my business logic (as a message handler) (finding what

Web API 2: OData 4: Actions returning 404

試著忘記壹切 提交于 2020-01-11 09:35:15
问题 I have an OData v4 action method which is not working; note however that it was working fine in OData v3 (I am obviously in the process of trying to update my project) OData Action Method: [HttpPost] public Translation Translate(ODataActionParameters parameters) { // Implementation } Configuration: ODataModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet<Page>("Pages"); //etc (Other Entity Sets) var pageEntityType = builder.EntityType<Page>(); var translateAction =

Is there a way to detect from which source an API is being called?

可紊 提交于 2020-01-11 08:52:07
问题 Is there any method to identify from which source an API is called? source refer to IOS application, web application like a page or button click( Ajax calls etc). Although, saving a flag like (?source=ios or ?source=webapp) while calling api can be done but i just wanted to know is there any other better option to accomplish this? I also feel this requirement is weird, because in general an App or a web application is used by n number of users so it is difficult to monitor those many API

Catch 404 errors in Asp.net Web API

喜欢而已 提交于 2020-01-11 08:16:37
问题 I am trying to catch 404 errors which are returned by the Asp.net Web API server. However, Application_Error from inside Global.asax is not catching them. Is there a way to handle these errors? 回答1: You might want to take a look at Handling HTTP 404 Error in ASP.NET Web API which has a step by step example 回答2: I know this is old, but I was also just looking for this, and found a very easy way that seems to work, so thought I'd add incase this can help someone else. The solution I found, that

Regex in Route attribute - RESTful API ASP.NET Web API

◇◆丶佛笑我妖孽 提交于 2020-01-11 07:41:08
问题 I've got a problem with regular expressions in Route attribute. I'd like to create RESTful API, where you can specify start date and end date in URL to filter results. What I've done till now is: [HttpGet] [Route("date/{startDate:datetime:regex(\\d{4}-\\d{2}-\\d{2})}/{*endDate:datetime:regex(\\d{4}-\\d{2}-\\d{2})}")] [Route("date/{startDate:datetime:regex(\\d{4}/\\d{2}/\\d{2})}/{*endDate:datetime:regex(\\d{4}/\\d{2}/\\d{2})}")] public IEnumerable<Recommendation> GetRecommendationByDate

Thinktecture IdentityModel AuthenticationConfiguration Mapping for Cookie - how?

南笙酒味 提交于 2020-01-11 06:16:42
问题 I have a Web API based application currently set up using the amazing Thinktecture IdentityModel 4.5. It is set up for claims-based authentication, accepting a Basic auth credential sent in on the Authorization header. The javascript client saves the returned session token and uses this for subsequent requests by including it in the Authorization header preceded by Session as the scheme. The javascript client also saves the token to a cookie, for retrieval if the window is closed and reopened

JSON Deserialization - String Is Automatically Converted To Int

给你一囗甜甜゛ 提交于 2020-01-11 05:36:08
问题 When I deseiralize the JSON to the C# object below, either using Newtonsoft explicitly or via the model binding mechanism of ASP.NET Web Api, the string id value is automatically converted to int. I would expect it to throw an exception or raise an error as there is a type mismatch. Is this how JSON is supposed to work in the specs? If not, how can I prevent such an automatic conversion? JSON: {"id":"4", "name":"a"} C# model: int id; string name 回答1: This is a feature of Json.NET: when

Unable to load application or execute command 'Microsoft.AspNet.Server.Kestrel'

会有一股神秘感。 提交于 2020-01-11 02:28:06
问题 I am trying to deploy my ASP.NET 5 WebApi to a remote server (Windows server 2008 R2) and am having trouble getting it to run correctly with IIS. project.json { "webroot": "wwwroot", "version": "1.0.0-*", "dependencies": { "App.Data": "1.0.0-*", "App.Model": "1.0.0-*", "App.Repository": "1.0.0-*", "App.ViewModel": "1.0.0-*", "AutoMapper": "4.1.1", "Microsoft.AspNet.Authentication": "1.0.0-rc2-16009", "Microsoft.AspNet.Authentication.JwtBearer": "1.0.0-rc2-16009", "Microsoft.AspNet.Diagnostics

Manually validate Model in Web api controller

做~自己de王妃 提交于 2020-01-10 19:50:13
问题 I have a class called 'User' and a property 'Name' public class User { [Required] public string Name { get; set; } } And api controller method is public IHttpActionResult PostUser() { User u = new User(); u.Name = null; if (!ModelState.IsValid) return BadRequest(ModelState); return Ok(u); } How do i manually validate the User object so the ModelState.IsValid return false to me? 回答1: You can use the Validate() method of the ApiController class to manually validate the model and set the

Web API Routing - multiple actions were found that match the request

末鹿安然 提交于 2020-01-10 19:30:05
问题 I got this Route: routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { id = UrlParameter.Optional } ); And this Actions: [System.Web.Http.HttpPost] [System.Web.Http.ActionName("GetLoginSeed")] public object GetLoginSeed() [System.Web.Http.HttpPost] [System.Web.Http.AllowAnonymous] [System.Web.Http.ActionName("Authenticate")] public object PerformLogin(JObject jr) This is the Post Request: http://localhost:61971/api/Login/GetLoginSeed Why I always get an