Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // AccountController.cs
- [Route("/account"), ApiController]
- public class AccountController : ControllerBase
- {
- [HttpPost("backendLogin"), AllowAnonymous]
- public async Task<ActionResult<LoginResponse>> BackendLogin(LoginRequest lr)
- {
- await Task.CompletedTask.ConfigureAwait(false); // do some business logic
- return Ok(new LoginResponse {UserId = "123"});
- }
- // Models
- public class LoginRequest {
- public string Email { get; set; }
- public string Password { get; set; }
- }
- public class LoginResponse {
- public string UserId { get; set; }
- }
- }
- // Startup.cs
- public void ConfigureServices(IServiceCollection services) {
- services.AddMvcCore()
- .AddJsonFormatters(settings => {
- settings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
- settings.DateFormatHandling = DateFormatHandling.IsoDateFormat;
- settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
- })
- .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
- services.Configure<ApiBehaviorOptions>(options => {
- // options.SuppressConsumesConstraintForFormFileParameters = true;
- // options.SuppressInferBindingSourcesForParameters = true;
- // options.SuppressModelStateInvalidFilter = true;
- });
- }
- public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
- if (env.IsDevelopment()) {
- app.UseDeveloperExceptionPage();
- }
- app.UseMvc();
- }
Add Comment
Please, Sign In to add comment