小编sko*_*jen的帖子

如何在实体框架中使用连接字符串指定用户名

我的 ASP.Net Core 应用程序不断尝试使用“默认”用户名登录数据库,即使我在我正在使用的连接字符串中指定了不同的用户。那就是我不断收到相同的异常,它说:

处理请求时发生未处理的异常。SqlException: 无法打开登录请求的数据库“testDB”。登录失败。用户 'DESKTOP-555DDD\skorejen' 登录失败

即使我使用的连接字符串定义了不同的用户名。

如何修复它以便我的应用程序使用连接字符串指定的用户名登录?

连接字符串:

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=testDB;User Id=myusername;Trusted_Connection=True;"
  },
Run Code Online (Sandbox Code Playgroud)

ASP.Net Core Startup.cs 文件:

public void ConfigureServices(IServiceCollection services)
        {
             services.AddDbContext<OrderContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
        }
Run Code Online (Sandbox Code Playgroud)

c# sql-server entity-framework asp.net-core

2
推荐指数
2
解决办法
5669
查看次数

从 Flutter 请求 ASP.Net Core 3.0 的错误请求 400

我正在尝试连接 Flutter 的 HttpClient 以从我在 ASP.Net Core 3.0 上运行的本地服务器获取数据。问题是我每次尝试时都会收到错误 400(错误请求)。

这是颤振代码:

    String token = await SharedPreferencesService.getStringFromSF('idToken');
    var client = new HttpClient();
    client.badCertificateCallback =
        (X509Certificate cert, String host, int port) => true;

    HttpClientRequest request =
        await client.getUrl(Uri.parse('https://10.0.2.2:44383/weatherforcast'));
    request.headers.add('idToken', token);

    HttpClientResponse response = await request.close();
    String reply = await response.transform(utf8.decoder).join();
Run Code Online (Sandbox Code Playgroud)

asp.net core 3.0 端点:

    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : ControllerBase
    {
        [HttpGet]
        public User Get()
        {
            return new User { UserId = 1332, Username = "Michal" };
        }
    }
Run Code Online (Sandbox Code Playgroud)

错误

<HTML><HEAD><TITLE>Bad …
Run Code Online (Sandbox Code Playgroud)

android flutter asp.net-core

2
推荐指数
2
解决办法
2531
查看次数