0

How to get value from api request in startup ConfigureServices C# mvc .net core 3

string page = HttpContext.Request.Query["page"].ToString();
            string conn = null; 
            string req = ; //I want to get request value
            foreach (ConnectionStringSettings c in System.Configuration.ConfigurationManager.ConnectionStrings)
            {
                if(c.ConnectionString == req)
                {
                    conn = c.ConnectionString;
                }

            }
            services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(Configuration.GetConnectionString(conn)));
  • 2
    ConfigureServices occurs on application initialization. This gets the application ready for use. The executing code does not have access to an http request at this point. – Igor Oct 20 '20 at 13:07
  • See the marked duplicate, I think this is what you are asking for. You just have to extend it to make use of the query string. – Igor Oct 20 '20 at 13:12

0 Answers0