asp.net-web-api

StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1,

百般思念 提交于 2020-08-07 09:01:28
问题 I use Web api selef host: public class TestController : ApiController { [HttpPost] public void Testp([FromBody]string title) { Console.WriteLine("Post"); } } this is simple controller and this is my client: client.BaseAddress = new Uri("http://localhost:1010"); const string englishTitle = "TesteDelete"; var post = client.PostAsync("Test/Testp", new { title = englishTitle }, new JsonMediaTypeFormatter()); var result = post.Result; if (result.IsSuccessStatusCode) { } else { string content =

Difference between AuthorizeAttribute and IAuthenticationFilter

亡梦爱人 提交于 2020-08-04 06:02:29
问题 In ASP.Net Web API 2 (Owin), what is the difference between IAuthenticationFilter and AuthorizeAttribute ? Currently I have implemented my authorization by creating my own AuthorizeAttribute like this: public class IntegratedAuthorization : AuthorizeAttribute { protected override bool IsAuthorized(System.Web.Http.Controllers.HttpActionContext actionContext) { bool returnValue = false; if (actionContext.Request.Headers.Authorization != null) { if (actionContext.Request.Headers.Authorization

Angular 6 Asp.Net (not Core) Web Api CORS request fails

情到浓时终转凉″ 提交于 2020-08-02 07:18:48
问题 I'm building a .Net Web Api that will be consumed by Angular 6 client but for any reason I'm not being able to make it to work in my development environment. I started with an extremely simple Web Api that just does nothing but returns a string (with communication between frontend and backend testing purposes): // GET: api/Login public IEnumerable<string> Get() { return new string[] { "Now it works!" }; } // POST: api/Login public void Post([FromBody]string value) { string strTest = "I'm

Angular 6 Asp.Net (not Core) Web Api CORS request fails

只谈情不闲聊 提交于 2020-08-02 07:18:27
问题 I'm building a .Net Web Api that will be consumed by Angular 6 client but for any reason I'm not being able to make it to work in my development environment. I started with an extremely simple Web Api that just does nothing but returns a string (with communication between frontend and backend testing purposes): // GET: api/Login public IEnumerable<string> Get() { return new string[] { "Now it works!" }; } // POST: api/Login public void Post([FromBody]string value) { string strTest = "I'm

C# Web - localhost:port works, 127.0.0.1:port doesn't work

与世无争的帅哥 提交于 2020-07-31 07:08:05
问题 I just finished adding C# Web API components (Web API Models & Controllers) to a localhost copy of an existing project. This Web API's GET-methods should be called from an Android app. In this link it's explained I should use 10.0.2.2 on the Android Emulator to get the computer's 127.0.0.1 . When I did this, it didn't work for my HttpRequest in the Android app. So I went to the Android browser and typed it directly, and it also didn't work. Then I tried using 127.0.0.1 instead of localhost in

Web Api Dash in variable name model binder

自闭症网瘾萝莉.ら 提交于 2020-07-20 10:29:11
问题 I would like to implement Mailgun's webhooks into my .Net Web API application, but some of the parameters they POST have dash'es in them. How do I get around that? Example of what they post: client-type=browser&city=San+Francisco&domain=telzio.com&device-type=desktop&my_var_1=Mailgun+Variable+%231&country=US&region=CA&client-name=Chrome&user-agent=Mozilla%2F5.0+%28X11%3B+Linux+x86_64%29+AppleWebKit%2F537.31+%28KHTML%2C+like+Gecko%29+Chrome%2F26.0.1410.43+Safari%2F537.31&client-os=Linux&my-var

Windows Authentication and Angular 7 application

醉酒当歌 提交于 2020-07-19 11:01:49
问题 I have developed intranet application Backend: ASP.NET WEB API-2 (All controllers have Authorize attribute), Frontend: Angular 7 (after prod build I moved generated scripts to my backend project): .... <app-root> <div id="preloader"></div> </app-root> <script type="text/javascript" src="~/Scripts/SPA/runtime.26209474bfa8dc87a77c.js"></script> <script type="text/javascript" src="~/Scripts/SPA/es2015-polyfills.bda95d5896422d031328.js" nomodule></script> <script type="text/javascript" src="~

Use custom validation responses with fluent validation

≯℡__Kan透↙ 提交于 2020-07-17 08:05:44
问题 Hello I am trying to get custom validation response for my webApi using .NET Core. Here I want to have response model like [{ ErrorCode: ErrorField: ErrorMsg: }] I have a validator class and currently we just check ModalState.IsValid for validation Error and pass on the modelstate object as BadRequest. But new requirement wants us to have ErrorCodes for each validation failure. My sample Validator Class public class TestModelValidator : AbstractValidator<TestModel>{ public TestModelValidator

Use custom validation responses with fluent validation

安稳与你 提交于 2020-07-17 08:05:12
问题 Hello I am trying to get custom validation response for my webApi using .NET Core. Here I want to have response model like [{ ErrorCode: ErrorField: ErrorMsg: }] I have a validator class and currently we just check ModalState.IsValid for validation Error and pass on the modelstate object as BadRequest. But new requirement wants us to have ErrorCodes for each validation failure. My sample Validator Class public class TestModelValidator : AbstractValidator<TestModel>{ public TestModelValidator

Use custom validation responses with fluent validation

孤人 提交于 2020-07-17 08:05:06
问题 Hello I am trying to get custom validation response for my webApi using .NET Core. Here I want to have response model like [{ ErrorCode: ErrorField: ErrorMsg: }] I have a validator class and currently we just check ModalState.IsValid for validation Error and pass on the modelstate object as BadRequest. But new requirement wants us to have ErrorCodes for each validation failure. My sample Validator Class public class TestModelValidator : AbstractValidator<TestModel>{ public TestModelValidator