Guest User

Untitled

a guest
Jul 19th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. // AccountController.cs
  2.  
  3. [Route("/account"), ApiController]
  4. public class AccountController : ControllerBase
  5. {
  6. [HttpPost("backendLogin"), AllowAnonymous]
  7. public async Task<ActionResult<LoginResponse>> BackendLogin(LoginRequest lr)
  8. {
  9. await Task.CompletedTask.ConfigureAwait(false); // do some business logic
  10. return Ok(new LoginResponse {UserId = "123"});
  11. }
  12.  
  13. // Models
  14.  
  15. public class LoginRequest {
  16. public string Email { get; set; }
  17. public string Password { get; set; }
  18. }
  19.  
  20. public class LoginResponse {
  21. public string UserId { get; set; }
  22. }
  23. }
  24.  
  25. // Startup.cs
  26.  
  27. public void ConfigureServices(IServiceCollection services) {
  28. services.AddMvcCore()
  29. .AddJsonFormatters(settings => {
  30. settings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
  31. settings.DateFormatHandling = DateFormatHandling.IsoDateFormat;
  32. settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
  33. })
  34. .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
  35.  
  36. services.Configure<ApiBehaviorOptions>(options => {
  37. // options.SuppressConsumesConstraintForFormFileParameters = true;
  38. // options.SuppressInferBindingSourcesForParameters = true;
  39. // options.SuppressModelStateInvalidFilter = true;
  40. });
  41. }
  42.  
  43. public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
  44. if (env.IsDevelopment()) {
  45. app.UseDeveloperExceptionPage();
  46. }
  47. app.UseMvc();
  48. }
Add Comment
Please, Sign In to add comment