【发布时间】:2017-09-18 20:51:38
【问题描述】:
我有一个简单的 ASP.net webform 应用程序,带有用于身份验证的 identity+owin。这工作得很好。
现在我需要创建一个 webservice(.asmx) 来让我的用户通过服务进行身份验证。因此服务可以接受用户名+密码并对其进行身份验证。
这是对 android 应用程序的用户进行身份验证所必需的。
我不想使用任何其他身份验证,例如 google 或 facebook..etc...
也没有 MVC。
谁能指点我的解决方案。
下面是我的 login.aspx 页面的代码。我应该在我的网络服务中添加什么?
Android 应用程序开发人员是另一个人。我只需要确保我的网络服务工作正常。
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");
}
【问题讨论】:
标签: c# android asp.net web-services asp.net-identity