Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Net;
- using System.Net.Http;
- using System.Net.Http.Headers;
- using System.Threading.Tasks;
- namespace Vaersacces
- {
- //Plantilla para datos del Login
- public class LoginData
- {
- string user;
- string pass;
- public LoginData(string user, string pass)
- {
- this.user = user;
- this.pass = pass;
- }
- }
- //Clase Asíncrona para llamar al Web Service
- public class AsyncTaskLogin
- {
- //Instancia de un nuevo cliente
- static HttpClient client = new HttpClient();
- //Se asignan los datos a la nueva instancia
- static async Task RunAsync()
- {
- client.BaseAddress = new Uri("dirección de la api");
- client.DefaultRequestHeaders.Accept.Clear();
- client.DefaultRequestHeaders.Accept.Add(
- new MediaTypeWithQualityHeaderValue("application/json"));
- }
- //Método para postear un objeto tipo LoginData en formato Json
- static async Task<Uri> CreateLoginAsync(LoginData login)
- {
- HttpResponseMessage response = await client.PostAsJsonAsync(
- "login/users", login);
- response.EnsureSuccessStatusCode();
- return response.Headers.Location;
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace Vaersacces
- {
- public partial class WebForm1 : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- //Evento de Login
- protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
- {
- //Se comprueba si el usuario es correcto
- bool authenticated = false;
- authenticated = LoginCorrecto(Login1.UserName, Login1.Password);
- e.Authenticated = authenticated;
- if (authenticated)
- {
- Response.Redirect("Default.aspx");
- }
- //Método para comprobar la veracidad del usuario
- bool LoginCorrecto(string user, string pass)
- {
- LoginData data = new LoginData(user, pass);
- AsyncTaskLogin login = new AsyncTaskLogin();
- var uri = await login.CreateLoginAsync(data);
- return false;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment