sql-server - 无法打开登录请求的数据库“Auth”。登录失败。用户“ServerName”登录失败
问题描述
我正在.net Core 2.1 中开发一个应用程序,我在其中应用 aspnet 身份用户的身份验证。数据库在服务器上,而我在 .net 核心中的程序在另一台带有 IIS 的服务器上。我的程序在本地正常工作,但是当我将它部署到我的服务器并尝试访问我的一种方法来执行登录时,我收到以下错误:
无法打开登录请求的数据库“Auth”。登录失败。用户“[NAME-OF-SERVER-WITH-IIS]”登录失败。
奇怪的是,在我的连接字符串中,我指定我要连接的用户是“sa”。
Startup.cs - ConfigureServices 方法
public void ConfigureServices(IServiceCollection services)
{
String con = "Data Source=<Servername>;Initial Catalog=Auth;Persist Security Info=True;User ID=sa;Password=<Password>;Trusted_Connection=True;MultipleActiveResultSets=true";
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(con,
b => b.MigrationsAssembly("Auth")));
...
}
AuthController.cs - 登录方法
[HttpPost("Login")]
public async Task<IActionResult> Login([FromBody]CredentialsViewModel credentials)
{
try
{
if (!ModelState.IsValid)
return BadRequest(ModelState);
var identity = await GetClaimsIdentity(credentials.UserName, credentials.Password);
if (identity == null)
return BadRequest(Errors.AddErrorToModelState("login_failure", "Invalid username or password.", ModelState));
var jwt = await Tokens.GenerateJwt(identity, jwtFactory, credentials.UserName, jwtOptions, new JsonSerializerSettings { Formatting = Formatting.Indented });
return new OkObjectResult(jwt);
}
catch (Exception e)
{
return new OkObjectResult(e.Message);
}
}
解决方案
推荐阅读
- awk - 如何在具有多行的两个方括号之间进行正则表达式?(grep|awk|python)
- javascript - TestCafe - 由于 my-local-ip 或代理的前缀,无法连接第 3 方 uri
- sql - 加速分区 ROW_NUMBER()
- ios - 使用 CarPlay 框架的 CarPlay 应用在 iOS 13 或更早版本上崩溃
- docker-compose - 为了让 Redash 连接到 AWS Redis,我应该在 REDASH_REDIS_URL 中添加什么?
- python - 从嵌套字典中的键获取下一个值
- scala - Uploading gatling report to s3
- arrays - 比较两个数组,如果值在数组中,则添加到列表中,如果不是,则将值添加到另一个列表中。没有重复
- java - 当我尝试加载新的 FXML 并为其设置新场景时,如何修复我的标签为空?
- asp.net - 使用 ASP.NET Azure 应用服务的早期提示或 HTTP/2 推送