asp.net-web-api2

Does IExceptionLogger deprecate the need for ExceptionFilterAttribute in Web API 2?

◇◆丶佛笑我妖孽 提交于 2019-12-04 02:19:08
Following the discussion from the official documentation on implementing an IExceptionLogger ( http://www.asp.net/web-api/overview/testing-and-debugging/web-api-global-error-handling ) which links to the (now dated?) article on implementing an ExceptionFilterAttribute ( http://www.asp.net/web-api/overview/testing-and-debugging/exception-handling ), is there any reason to register a global ExceptionFilterAttribute if you register a service for IExceptionLogger ? I did and when debugging an exception generated in a controller action, both implementations handled the exception. So

Web API 2 Http Post Method

走远了吗. 提交于 2019-12-04 02:18:56
I am disgusted not have found a solution to this problem. I started creating a new api using Web API 2 and just cannot get the POST and PUT to work. The Get all and Get single item works perfectly fine. There are no related articles anywhere, and those that i've found relates only to Gets and Web API, but not Web API 2. Any assistance would do please. // POST: api/checkOuts [HttpPost] [ResponseType(typeof(checkOut))] [ApiExplorerSettings(IgnoreApi = true)] public async Task<IHttpActionResult> PostcheckOut(checkOut co) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.checkOuts

Is it safe to store a sensitive data in Local Stoarge or session storage? Localstorage allows to any attacks for sensitive data

北战南征 提交于 2019-12-04 01:59:32
In web application , How secure is local storage in Html5 or else is there any other way to secure the sensitive data in local storage. Project Structure: Front End: Html5,Angular js, Middletier: Asp.net webApi , BackEnd :Sql Server. Once user login into the page, that credentials is encrypted by using some cryptography algorithms.It will be stored in db. After that every child action like products list, order details, book history ,add product need to validate that. While refresh after the page, data gets lossed so need to persist the data so i have choose localstorage. stored the username

Web API ModelBinding From URI

℡╲_俬逩灬. 提交于 2019-12-04 01:22:27
So I have a custom Model Binder implemented for DateTime type and I register it like below: void Application_Start(object sender, EventArgs e) { // Code that runs on application startup GlobalConfiguration.Configuration.BindParameter(typeof(DateTime), new CurrentCultureDateTimeAPI()); } and then I have setup 2 sample actions to see if my custom model binding takes place: [HttpGet] public void BindDateTime([FromUri]DateTime datetime) { //http://localhost:26171/web/api/BindDateTime?datetime=09/12/2014 } [HttpGet] public void BindModel([FromUri]User user) { //http://localhost:26171/web/api

Exception handling in Web API

我与影子孤独终老i 提交于 2019-12-04 01:00:02
问题 In my Web API project, I created sub projects (class libraries) where I handle actual data handling operations. My backend database is DocumentDB. My question is how do I tell my Web API action methods of any errors I may encounter within data methods in my class libraries? Once my Web API method knows about the error, I can just return Http status 500 or something like that but I'm not sure what I should have in the catch part (see below) and how I can notify the calling Web API method of

Route all Web API requests to one controller method

跟風遠走 提交于 2019-12-04 00:54:24
Is it possible to customize ASP.NET Web API's routing mechanism to route all requests to the API to one controller method? If a request comes in to www.mysite.com/api/products/ or www.mysite.com/api/otherResource/7 All would be routed to my SuperDuperController's Get() method? I ran into a case where I needed to do this. (Web API 2) I first looked into creating custom IHttpControllerSelector and IHttpActionSelector s. However, that was a bit of a murky way around. So I finally settled on this dead simple implementation. All you have to do is setup a wildcard route. Example: public class

Validate model on specific string values

≡放荡痞女 提交于 2019-12-03 23:56:39
I'm working on a Web API 2 project. besides the requirement that some properties are required, some only can have specific values. One option is that I could try to save the model to the database (EF6) and create some logic while saving, but I think it is better to validate if the correct value is set before I make a call to the database. Does data annotations provide an attribute like Range but then for specific string values like in the example below? Or do I have to write my own validator attribute? public class Person { public int PersonID { get; set; } [Required] public string FirstName {

Web Api Controller in other project, route attribute not working

旧街凉风 提交于 2019-12-03 23:12:13
I have a solution with two projects. One Web Api bootstap project and the other is a class library. The class library contains a ApiController with attribute routing. I add a reference from web api project to the class library and expect this to just work. The routing in the web api is configured: config.MapHttpAttributeRoutes(); The controller is simple and looks like: public class AlertApiController:ApiController { [Route("alert")] [HttpGet] public HttpResponseMessage GetAlert() { return Request.CreateResponse<string>(HttpStatusCode.OK, "alert"); } } But I get a 404 when going to the url "

No MediaTypeFormatter is available to read an object of type 'Advertisement' in asp.net web api

时光总嘲笑我的痴心妄想 提交于 2019-12-03 23:00:35
I have a class that name is Advertisement: public class Advertisement { public string Title { get; set; } public string Desc { get; set; } } and in my controller: public class OrderController : ApiController { public UserManager<IdentityUser> UserManager { get; private set; } // Post api/Order/Test [Route("Test")] public IHttpActionResult Test(Advertisement advertisement) { var currentUser = User.Identity.GetUserId(); Task<IdentityUser> user = UserManager.FindByIdAsync(currentUser); return Ok(User.Identity.GetUserId()); } but when I test it with Postman I face this error, "Message": "The

Validate OAuth bearer token with form post

。_饼干妹妹 提交于 2019-12-03 21:57:12
I've created a OData based web back-end using Web API 2. This works really well, using AuthorizeAttribute on controllers. I'd like to be able to upload a files, via a standard html form and a submit. We are passing the OAuth token, which would normally be passed in the header of an OData request, as a hidden input field. Question: How do you validate this in the controller? Then you need to un-protect the token, then from the "ticket" you check if there is principal and if it is authenticated (check property IsAuthenticated). Use the code below inside your controller: string token = "Your