asp.net-web-api2

How to access the database from the api controller?

我是研究僧i 提交于 2019-12-13 17:05:30
问题 I am doing a mobile app with Angular and MVC. I am doing my app calling some dummy data from the json model in the web api. Check my code below: private IEnumerable<JsonModel> events = new JsonModel[] { new JsonModel {Id = 1, Title = "title1"} new JsonModel {Id = 2, Title = "title2"} }; // GET api/<controller> public IEnumerable<JsonModel> Get() { return events; } // GET api/<controller>/5 public JsonModel Get(int id) { return events.FirstOrDefault(e => e.Id == id ); } What I want to do now

Web API 2 CORS Won't Allow IP Addresses as Origins

一个人想着一个人 提交于 2019-12-13 16:24:11
问题 I have a Web API 2 application with CORS authentication enabled. Locally I'm running two sites, a SPA site and the web API, both on port 80, using different host headers. Everything works fine. However, I'm trying to test on a machine that has no domain, so I have to use IP addresses with different ports for the two sites. No matter what I do, the web API gives the good old "No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://xxx.xxx.xxx.xxx:8090' is

C# Web API POST parameter FromBody is always null

被刻印的时光 ゝ 提交于 2019-12-13 14:31:47
问题 I've been scouring the web for hours and tried many different solutions also described here on StackOverflow. I know similar questions have been asked before, but none of the answers or comments have worked for me. The problem: I have a .NET Web API that has a Post-method with some parameters. One of the parameters is a complex object that is supposed to be read from the body (that is JSON). However, this object is always null . This is my code: // POST api/worksheets/post_event/true/false

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

百般思念 提交于 2019-12-13 11:58:26
问题 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

How to remove Allow header from Http Response?

心不动则不痛 提交于 2019-12-13 09:54:44
问题 I have API which is valid for POST/GET/PUT verb but if hacker intercepts the request and change method to 'OPTIONS' instead of 'GET', he will get below error in http response - Allow: GET,POST,PUT { "Message": "The requested resource does not support http method 'OPTIONS'." } This allows hacker to identify what verbs supported by API. I have to restrict this header in response. I tried removing 'WebDav' module but it still showing same message. I don't want hacker to see this message and

Large File (1-3GB) upload to SQL via WebApi [closed]

青春壹個敷衍的年華 提交于 2019-12-13 09:37:11
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . I have a JS/HTML5 front end that calls a C# WebAPI to upload a large file (1-3GB) that needs to be encrypted and then stored in a SQL DB. My restrictions are that I can't store file unecnrypted and it can't be stored outside of SQL. I also can't use SQL FileStream. For the WebAPI,

How to call API in asp.net MVC5

筅森魡賤 提交于 2019-12-13 09:35:27
问题 I have asp.net mvc5 project that I want to call another API using JSON, and I want to call that API from my Controller action because I need to do some hashing in there, It's my first time doing this, and I need to send the request in JSON and also get responses in JSON all of that using the controller action. 回答1: If your method is POST : string uri = "yourdomain/api/controller/method; var client = new HttpClient(); var values = new Dictionary<string, string>() { {"username", SecurityHelper

ASP.NET Web Api 2 - Internet Explorer: The process cannot access the file because it is being used by another process

偶尔善良 提交于 2019-12-13 07:38:11
问题 I have a Restful ASP.NET Web API 2 with the following method that returns a HttpResponseMessage with an image as content: [AllowAnonymous] [HttpGet, Route("{id}/image/"] public HttpResponseMessage GetImage(int id) { try { var artwork = Service.GetSingle(id); if(!isValidArtwork(artwork)) { Request.CreateResponse(HttpStatusCode.NotFound); } string mediaHeaderValue; switch (Path.GetExtension(artwork.filePath)) { case ".jpg": mediaHeaderValue = "image/jpg"; break; case ".jpeg": mediaHeaderValue =

$inlinecount not working on ApiController using ApplyTo

淺唱寂寞╮ 提交于 2019-12-13 07:37:10
问题 I'm trying to use the OData filtering and paging capabilities in a standard Web API 2.2 ApiController . For this, I have to rewrite the request URL to conform to the OData v4 standards. My controller looks like this: public GridPage Get([FromUri] GridSearchCriteria criteria) { Request.RequestUri = ... // convert querystring to OData v4 var context = new ODataQueryContext(MyEdmModel.Instance, typeof(Delivery), null); ODataQueryOptions<Delivery> options = new ODataQueryOptions<Delivery>(context

Not getting response when register is successful

[亡魂溺海] 提交于 2019-12-13 07:14:09
问题 I have a Web API 2 register method as follows :- [AllowAnonymous] [Route("Register")] public async Task<IHttpActionResult> Register(RegisterBindingModel model) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var user = new ApplicationUser() { UserName = model.Email, Email = model.Email }; IdentityResult result = await UserManager.CreateAsync(user, model.Password); if (!result.Succeeded) { return GetErrorResult(result); } return Ok(); } and an angular Controller that posts to