我目前正在开展MVC5项目。以前的项目工作托管数据库.i已创建数据库本地我有插入用户值登录。后创建本地数据库我试图连接其登录不工作。 HomeSqlDBRepository用于读取字符串数据库的值 这里登录方法登录代码
public class LoginRepository
{
HomeSqlRepository _repository = new HomeSqlRepository();
public async Task<LoginModelViewModel> ValidateLogin(LoginModel model) {
model.ThrowIfNull();
var ConnectionString = AppSettingsReader.ReadString("thenna");
IDictionary<string, object> dictionary = new Dictionary<string, object>();
dictionary.Add("username", model.UserEmail);
dictionary.Add("password", model.Password);
return await _repository.GetItemAsync<LoginModelViewModel>("dbo.validateuser", dictionary);
}
public async Task<LoginModelViewModel> GetProfileDetails(int uid)
{
var ConnectionString = AppSettingsReader.ReadString("thenna");
IDictionary<string, object> dictionary = new Dictionary<string, object>();
dictionary.Add("uid", uid);
return await _repository.GetItemAsync<LoginModelViewModel>("dbo.GetUserProfile", dictionary);
}
homesqlrepository
public abstract class HomeSqlDBRepository
{
public string ConnectionString { get; set; } = AppSettingsReader.ReadString("thenna");
const int MaxItemCount = 1000;
public enum SqlExecuteType
{
Scalar, NonQuery, Reader
}
public async Task<string> ExecuteSqlAsync(string procname, SqlExecuteType executiontype, IDictionary<string, string> parameters)
{
string ret = "";
using (SqlConnection sqlConn = new SqlConnection(ConnectionString))
{
using (SqlCommand sqlCmd = new SqlCommand(procname, sqlConn))
{
sqlCmd.CommandType = CommandType.StoredProcedure;
foreach (KeyValuePair<string, string> kvp in parameters)
{
sqlCmd.Parameters.AddWithValue(kvp.Key, kvp.Value);
}
sqlConn.Open();
if (executiontype == SqlExecuteType.Scalar)
ret = (await sqlCmd.ExecuteScalarAsync()).ToString();
else if (executiontype == SqlExecuteType.NonQuery)
ret = (await sqlCmd.ExecuteNonQueryAsync()).ToString();
sqlConn.Close();
}
}
Appsettings config
<add key="thenna" value="server=DESKTOP-QD6A981\SQLEXPRESS;database=montage;user id=sa;password=root;trusted_connection=false;" />-
<add key="CustomAuthentication.LoginUrl" value="/Account/LogOn" />
<add key="CustomAuthentication.Cookie.Name" value=".CUSTOM_AUTH" />
<add key="CustomAuthentication.Cookie.Expiration" value="1" />
<add key="CustomAuthentication.Cookie.Timeout" value="20" />
使用云配置管理器的AppSettingsReader
public static class AppSettingsReader
{
public static string ReadString(string key)
{
try
{
return CloudConfigurationManager.GetSetting(key).ToString();
}
catch(System.Exception ex)
{
throw ex;
}
}
}
我确实错误登录而不是工作。什么云配置管理器?为什么要用这个?