asp.net identity webservice android

问题描述:

我有一个简单的ASP.net webform应用程序身份+ owin进行身份验证。这工作非常好。asp.net identity webservice android

现在我需要创建一个web服务(.asmx)来让我的用户通过服务进行身份验证。所以服务可以接受用户名和密码并验证它们。

这是验证Android应用程序的用户所必需的。

我不希望使用任何其他身份验证像谷歌或facebook..etc ...

而且没有任何MVC。

任何人都可以指出我的解决方案。

波纹管是我的login.aspx页面的代码。我应该在我的web服务中放入什么?

Android应用程序开发人员是另一个人。我只需要确保我的web服务工作正常。

protected void SignIn(object sender, EventArgs e) 
     { 
      var userStore = new UserStore<IdentityUser>(); 
      var userManager = new UserManager<IdentityUser>(userStore); 
      var user = userManager.Find(UserName.Text, Password.Text); 

      if (user != null) 
      { 
       var authenticationManager = HttpContext.Current.GetOwinContext().Authentication; 
       var userIdentity = userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie); 

       authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, userIdentity); 


       string cs = ConfigurationManager.ConnectionStrings["DB_6"].ConnectionString; 
       using (SqlConnection conn = new SqlConnection(cs)) 
       { 
        SqlCommand cmd = new SqlCommand("spGetUser", conn); 
        SqlDataAdapter Adpt = new SqlDataAdapter(); 
        DataSet login = new DataSet(); 
        try 
        { 
         cmd.CommandType = CommandType.StoredProcedure; 
         cmd.Parameters.AddWithValue("@PEmail", UserName.Text); 
         Adpt.SelectCommand = cmd; 
         Adpt.Fill(login); 
         foreach (DataRow dr in login.Tables[0].Rows) 
         { 
          string PFName = login.Tables[0].Rows[0]["PFName"].ToString(); 
          string PLName = login.Tables[0].Rows[0]["PLName"].ToString(); 
          string PType = login.Tables[0].Rows[0]["PType"].ToString(); 
          int PersonID = int.Parse(login.Tables[0].Rows[0]["PersonID"].ToString()); 
          using (SqlConnection con = new SqlConnection(cs)) 
          { 

           SqlCommand cmd1 = new SqlCommand("spInsLoc", con); 
           cmd1.CommandType = CommandType.StoredProcedure; 
           cmd1.Parameters.Add("@PersonID", SqlDbType.Int).Value = PersonID; 
           cmd1.Parameters.Add("@OrgID", SqlDbType.Int).Value = 0; 
           cmd1.Parameters.Add("@Location", SqlDbType.NVarChar).Value = hdnLocation.Value; 
           cmd1.Parameters.Add("@strOwner", SqlDbType.VarChar).Value = UserName.Text; 
           cmd1.Parameters.Add("@dbTstamp", SqlDbType.DateTime2).Value = DateTime.Now; 
           con.Open(); 
           cmd1.ExecuteNonQuery(); 

          } 
         } 
        } 
        catch { } 
        finally { } 

       } 

       Response.Redirect("~/Login.aspx"); 
      } 
      else 
      { 
       StatusText.Text = "Invalid username or password."; 
       LoginStatus.Visible = true; 
      } 
     } 

protected void SignOut(object sender, EventArgs e) 
     { 
      var authenticationManager = HttpContext.Current.GetOwinContext().Authentication; 
      authenticationManager.SignOut(); 
      Response.Redirect("~/Login.aspx"); 
     } 

您需要使用文章&获取Web服务的方法。

创建新的android应用程序并使用抽象或原生Java库来获取Http Req。

这是请求的示例代码;

URL url; 
HttpURLConnection urlConnection = null; 
try { 
    url = new URL("http://yoursite.com?name=foo?pass=foo"); 

    urlConnection = (HttpURLConnection) url 
      .openConnection(); 

    InputStream in = urlConnection.getInputStream(); 

    InputStreamReader isw = new InputStreamReader(in); 

    int data = isw.read(); 
    while (data != -1) { 
     char current = (char) data; 
     data = isw.read(); 
     System.out.print(current); 
    } 
} catch (Exception e) { 
    e.printStackTrace(); 
} finally { 
    if (urlConnection != null) { 
     urlConnection.disconnect(); 
    }  
} 

并且您的Web服务将响应请求。

例如:yoursite.com?name=foo?pass=foo响应 - > TRUE或FALSE

+0

我已经更新的问题。请见。 –