asp.net-web-api

Accessing query string variables sent as POST in HttpActionContext

百般思念 提交于 2020-05-27 10:42:14
问题 I'm trying to access a query string parameter that was sent using the POST method (WebClient) to the Web API in ASP.NET MVC 5 (in an overridden AuthorizationFilterAttribute). For Get, I've used the following trick: var param= actionContext.Request.GetQueryNameValuePairs().SingleOrDefault(x => x.Key.Equals("param")).Value; However, once I use POST, this does work and the variable paran is set to null. I think that's because the query string method only applies to the url, not the body. Is

Onion Architecture Identity Framework

柔情痞子 提交于 2020-05-27 09:28:04
问题 I am following Onion Architecture. And in that I am using ASP.NET Identity Framework. Here is my Project Structure: 1-Core - Domain Classes //It contains my T4 template classes -- AppUser //It is Identity User. - Repository Interfaces - Service Interfaces 2-Infrastructure - Data //It contains my edmx file, I am using Db First approach. - Dependency Injection - Repository Interfaces Implementation - Service Interfaces Implementation 3-WebApi - Web Api Project 4-WebClient - My AngularJs App 5

Children processes created in ASP.NET Core Process gets killed on exit

前提是你 提交于 2020-05-24 21:13:29
问题 I'm spawning a child process in ASP.NET Core (.NET Framework) with Process class: var process = new Process { StartInfo = new ProcessStartInfo(executableDir) { Arguments = commandDefinition.CommandDef.ArgumentsAsString, RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, CreateNoWindow = true, WorkingDirectory = _contentPath, }, }; process.Start() As far as I understand when parent (ASP.Net Core) process gets killed, the children process should stay alive. I

asp.net web API HTTP PUT method

孤街醉人 提交于 2020-05-24 03:58:22
问题 I have some resource- UserProfile public UserProfile { public string Email{get;set;} public string Password{get;set;} } I want to change Email and Password separatly (only one for user at same time). I have web api controller for example /api/user/123 that handle requests in RESTful style. Follow the RESTful style i should have one method PUT which update the resource, but i have two task that update the same resource api/user/123. I need to add some feature to PUT request body like {email:

Change default type of numeric deserialization

醉酒当歌 提交于 2020-05-23 10:08:31
问题 While I was deserializing some JSON data to DataSet, the resultant dataset may lose its column schema. that means, When I deserialize some JSON, it populates the Dataset with Int64 objects rather than Int32. I would like it to choose Int32. I know, Json.NET by default reads integer values as Int64 because there is no way to know whether the value should be Int32 or Int64. JsonSerializerSettings settings = new JsonSerializerSettings() { Converters = { new PrimitiveJsonConverter() }, }; DataSet

Create user programmatically using C# ASP.NET MVC Identity

百般思念 提交于 2020-05-15 10:56:28
问题 I'm trying to add a user programmatically to ASP.NET MVC Identity. The error I'm encountering is: UserManager threw an exception of type 'System.NullReferenceException' This function is called through a POST not originating from this site. It sits right below public async Task<ActionResult> Register(RegisterViewModel model) in the AccountController. [AllowAnonymous] public async Task<bool> GenerateUser(string email) { var user = new ApplicationUser { UserName = email, Email = email }; string

Attempting ValidationAttribute in MVC4 that is asynchronous using Async, Task and Await

∥☆過路亽.° 提交于 2020-05-15 03:35:31
问题 I am attempting to write a Validation attribute in MVC4. The purpose is to check for the existence of an application reference (just a string that represents a key I wish to prevent a duplicate for). My data is accessed via WebAPI and because I am using 4.5 I wish to make this asynchronous if possible. I am perhaps not making the best or appropriate usage of async and await but I would like to know how to call my async method from the overridden IsValid method of the inherited Validation

Attempting ValidationAttribute in MVC4 that is asynchronous using Async, Task and Await

ⅰ亾dé卋堺 提交于 2020-05-15 03:35:25
问题 I am attempting to write a Validation attribute in MVC4. The purpose is to check for the existence of an application reference (just a string that represents a key I wish to prevent a duplicate for). My data is accessed via WebAPI and because I am using 4.5 I wish to make this asynchronous if possible. I am perhaps not making the best or appropriate usage of async and await but I would like to know how to call my async method from the overridden IsValid method of the inherited Validation

ASP.NET Core giving me Code 500 on Forbid()

北城以北 提交于 2020-05-14 17:25:49
问题 I tried to solve this for hours now and I can not find anything. Basicly I have a simple controller which roughly looks like this: [Route("v1/lists")] public class ListController : Controller { ... [HttpPost("{id}/invite")] public async Task<IActionResult> PostInvite([FromBody] string inviteSecret, [FromRoute] int id, [FromQuery] string userSecret) { if (!ModelState.IsValid) { return BadRequest(ModelState); } List list = await context.Lists.SingleOrDefaultAsync(l => l.ID == id); if (list ==

Use Redirect in Web Api Controller (HTTP 302 Found)

ⅰ亾dé卋堺 提交于 2020-05-14 16:52:31
问题 For some reason I am having lots of trouble trying to find out how to redirect ( HTTP 302 Found ) to an absolute URL from within a controller. I have tried this: this.Redirect("/assets/images/avatars/profile.jpg"); But I get an exception thrown Exception thrown: 'System.UriFormatException' in System.dll Additional information: Invalid URI: The format of the URI could not be determined. Every other answer I see on here doesn't seem to be available to me. I am using Web API and MVC 5 . 回答1: