asp.net-web-api2

Response to preflight request doesn't pass access control check (Angular2)

痞子三分冷 提交于 2019-12-05 02:48:00
I am getting below error on call to REST Web API in Asp.net. XMLHttpRequest cannot load http://localhost:54859/api/PostData . Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://localhost:3000 ' is therefore not allowed access. I am using Angular2 as Front end. In the back end, I have added following codes to enable CORS in WEB API. var corsAttr = new EnableCorsAttribute("*", "*", "*"); config.EnableCors(corsAttr); Everything works fine for Http get request,but the same not for Http Post

ModelState is always considered valid, regardless of null values in required fields

爱⌒轻易说出口 提交于 2019-12-05 02:31:40
I've been looking around and I think my solution is just fine but somehow the ModelState.IsValid property is always true . Consider the following code snippets: [Route("address")] [HttpPut] [ResponseType(typeof(UserViewModel))] public IHttpActionResult UpdateAddress([FromBody] UpdateAdressValidationModel model) { if (!ModelState.IsValid) { return BadRequest(ModelState); } // irrelevant code omitted } [TestMethod] public void UpdateAddress_WithoutStreet_ReturnsHttpCode400() { var userController = new UserController(new UserRepository(_context)); var addressInfo = new UpdateAdressValidationModel

Web API Swagger documentation export to PDF

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 02:09:17
In according to the documentation ( http://swagger.io/open-source-integrations/ ) there are plugins for Java to Export Swagger documentation to PDF , I just have a look the documentation but I can't see anything regarding .NET . My question is: is there something similar to the Java Plugin swagger2markup, swagger2markup-gradle-plugin in .NET or another way to export the PDF Documentation from WEB API? thanks 来源: https://stackoverflow.com/questions/40258287/web-api-swagger-documentation-export-to-pdf

Web Api HTTPPost not accepting int

随声附和 提交于 2019-12-05 01:34:08
I am trying to just pass in body a int and it does not work Why do I need to create a class with a property of type int ? (then it works) WORKS [HttpPost] [Route("api/UpdateMainReversed")] public IHttpActionResult UpdateMainVerified(DataAccess.Entities.RequestMain mainValues) { ....} DO NOT WORK [HttpPost] [Route("api/UpdateMainReversed")] public IHttpActionResult UpdateMainVerified(int mainId) { ....} Testing with Postman http://localhost:13497/api/UpdateMainReversed Body { "mainId" : 1615 } 1.Your [HttpPost] expects a int but from body you are passing a json object. you should pass json

How do I host/publish my .Net Core WebAPI on Ubuntu?

霸气de小男生 提交于 2019-12-05 01:10:04
问题 I am learning .Net Core. I have developed WebApplication using ASP.Net MVC and as it can be installed and run on Local IIS. What's the similar way to Host / Publish .Net Core WebApi in Ubuntu and Linux instead of running on specific port like 5000? Is docker helpful for that context? If yes then how can I use it? Is it possible to host / publish without docker? How can i Host / Publish without Docker? I also read following link and implemented all steps. Publish to a Linux Production

MVC Routes within WebAPI controller

眉间皱痕 提交于 2019-12-05 00:49:09
问题 Quick question regarding routes within MVC and WebAPI. I have added a route to route config.cs: routes.MapRoute( name: "ConfirmEmail", url: "ConfirmEmail/{userid}", defaults: new { controller = "Email", action = "ConfirmEmail" } ); This is registered in the global.asax as per normal: RouteConfig.RegisterRoutes(RouteTable.Routes); I am trying to generate a URL for use within an email which is sent as part of a function call within a WebAPI controller function. I am using the UrlHelper.Link

.Net Core WebAPI , Unable to post data with POSTMAN , error - 415 Unsupported MediaType

本小妞迷上赌 提交于 2019-12-05 00:23:06
I am testing my first .net Core WebAPI with Postman unknown media type error is occurring. What am I missing? This is my posting object public class Country { [Key] public int CountryID { get; set; } public string CountryName { get; set; } public string CountryShortName { get; set; } public string Description { get; set; } } This is the webapi controller [HttpPost] public async Task<IActionResult> PostCountry([FromBody] Country country) { if (!ModelState.IsValid) { return BadRequest(ModelState); } _context.Country.Add(country); try { await _context.SaveChangesAsync(); } catch

Web Api 2 Post - UrlHelper.Link must not return null

僤鯓⒐⒋嵵緔 提交于 2019-12-04 23:51:17
I have a basic web API 2 setup with some basic routing. Below is the default route and post for inserts. When I call the post the record is created perfectly in the database but the "CreatedAtRoute" call returns a 500 error stating: ExceptionMessage: "UrlHelper.Link must not return null." ExceptionType: "System.InvalidOperationException" Why would I receive this error? [RoutePrefix("api/casenotes")] public class CasenoteController : ApiController... // POST api/Casenote [Route("")] [ResponseType(typeof(client_admission_casenote))] public async Task<IHttpActionResult> Postclient_admission

WebAPi - unify error messages format from ApiController and OAuthAuthorizationServerProvider

可紊 提交于 2019-12-04 23:49:25
In my WebAPI project I'm using Owin.Security.OAuth to add JWT authentication. Inside GrantResourceOwnerCredentials of my OAuthProvider I'm setting errors using below line: context.SetError("invalid_grant", "Account locked."); this is returned to client as: { "error": "invalid_grant", "error_description": "Account locked." } after user gets authenticated and he tries to do "normal" request to one of my controllers he gets below response when model is invalid (using FluentValidation): { "message": "The request is invalid.", "modelState": { "client.Email": [ "Email is not valid." ], "client

Relation to users when these are stored in an external Identity provider service

可紊 提交于 2019-12-04 23:46:53
问题 I'm trying to create an API and a website client for it. Lately I've been reading a lot about OAuth2 as a security mechanism and companies that offers authentication as a service such as auth0.com or even Azure active Directory and I can see the advantages in using them Because I'm used to always having the users in the same database and tables with relationships to the Users table in the form of One to Many such as below public class User { public string subjectId { get; set; } public