asp.net-web-api

Web Api with OData v4 throwing exception on $select

让人想犯罪 __ 提交于 2020-01-13 03:23:26
问题 I'm using the latest version of WebApi and OData and everything is set up to work right. The only problem is when I try to use $select . It throws the error bellow Object of type 'System.Linq.EnumerableQuery`1[System.Web.OData.Query.Expressions.SelectExpandBinder+SelectAll`1[WebApplication1.Controllers.Person]]' cannot be converted to type 'System.Collections.Generic.IEnumerable`1[WebApplication1.Controllers.Person]'. I looked at the documentation and their suggestion is to use [Queryable] on

The Constraint Entry 'httpMethod' on the Route Must Have a String Value

夙愿已清 提交于 2020-01-12 23:32:53
问题 I have an asp.net Web API project, and in my WebApiConfig file, I have the following route defined: config.Routes.MapHttpRoute( name: "Web API Get", routeTemplate: "api/{controller}", defaults: new { action = "Get" }, constraints: new { httpMethod = new HttpMethodConstraint("GET") } ); For integration testing purposes, I want to make a request to an HttpSelfHostServer to verify that we are receiving the proper data back from the api call. I am making the HttpRequestMessage as follows: var

The Constraint Entry 'httpMethod' on the Route Must Have a String Value

偶尔善良 提交于 2020-01-12 23:32:45
问题 I have an asp.net Web API project, and in my WebApiConfig file, I have the following route defined: config.Routes.MapHttpRoute( name: "Web API Get", routeTemplate: "api/{controller}", defaults: new { action = "Get" }, constraints: new { httpMethod = new HttpMethodConstraint("GET") } ); For integration testing purposes, I want to make a request to an HttpSelfHostServer to verify that we are receiving the proper data back from the api call. I am making the HttpRequestMessage as follows: var

The Constraint Entry 'httpMethod' on the Route Must Have a String Value

半城伤御伤魂 提交于 2020-01-12 23:32:08
问题 I have an asp.net Web API project, and in my WebApiConfig file, I have the following route defined: config.Routes.MapHttpRoute( name: "Web API Get", routeTemplate: "api/{controller}", defaults: new { action = "Get" }, constraints: new { httpMethod = new HttpMethodConstraint("GET") } ); For integration testing purposes, I want to make a request to an HttpSelfHostServer to verify that we are receiving the proper data back from the api call. I am making the HttpRequestMessage as follows: var

Anti-Forgery Token Web Api 2

余生长醉 提交于 2020-01-12 17:54:14
问题 I have an AccountController for my Web Api site that uses the default implementation for the login: // POST: /Account/Login [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return View(model); } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var result = await SignInManager

Anti-Forgery Token Web Api 2

丶灬走出姿态 提交于 2020-01-12 17:52:09
问题 I have an AccountController for my Web Api site that uses the default implementation for the login: // POST: /Account/Login [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return View(model); } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var result = await SignInManager

Why ASP Net Core 2.2 do not release memory?

烈酒焚心 提交于 2020-01-12 15:50:00
问题 I'm testing ASP Net Core 2.2 using default project made from: Visual Studio > File > New > Project > ASP NET Core Web Application > Next > Create. Press IIS Express button on interface and automatically go to https://localhost:44356/api/values Edit : The point is, I'm testing ASP Net Core in case of brute force spamming from people. I have only modified this: [HttpGet] public ActionResult<IEnumerable<string>> Get() { return new string[] { "value1", "value2" }; } Edit : to this, I edited my

Why ASP Net Core 2.2 do not release memory?

杀马特。学长 韩版系。学妹 提交于 2020-01-12 15:47:10
问题 I'm testing ASP Net Core 2.2 using default project made from: Visual Studio > File > New > Project > ASP NET Core Web Application > Next > Create. Press IIS Express button on interface and automatically go to https://localhost:44356/api/values Edit : The point is, I'm testing ASP Net Core in case of brute force spamming from people. I have only modified this: [HttpGet] public ActionResult<IEnumerable<string>> Get() { return new string[] { "value1", "value2" }; } Edit : to this, I edited my

ASP.NET Core Identity does not inject UserManager<ApplicationUser>

蓝咒 提交于 2020-01-12 14:26:07
问题 I've got an older asp.net core identity database, and I want to map a new project (a web api) to it. Just for the test, I copied the Models folder, and the ApplicationUser file from the previous project (ApplicationUser simply inherits from IdentityUser, no changes whatsoever) - doing DB first seems to be a bad idea. I'm registering Identity in ConfigureServices (but I'm not adding it to the pipeline since my only intention is to use the UserStore) services.AddIdentity<ApplicationUser,

Web Api - How to detect when a response has finished being sent

情到浓时终转凉″ 提交于 2020-01-12 14:21:47
问题 In a web api method I am generating a file and then streaming it to the response like so public async Task<HttpResponseMessage> GetFile() { FileInfo file = generateFile(); var msg = Request.CreateResponse(HttpStatusCode.OK); msg.Content = new StreamContent(file.OpenRead()); msg.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); msg.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") {FileName = file.Name}; return msg; } because this a