locked
Implement Demo and Production server from same link RRS feed

  • Question

  • User812858302 posted

    Hello Pals,

    I wanted to use two db from same startup class the scenario is I have created one demo button link on my login page once I hit the demo I have to change the db.

    both the db has same table and function 

    1.Db1 normal login 

    2.demobd when clicked on demo link 

    Monday, January 11, 2021 10:46 AM

All replies

  • User475983607 posted

    The Demo should be a separate URL.  Your design approach runs the risk of production data making its way in the demo DB during run time.  

    If you cannot create a second domain for the demo then use configuration and an basic "if" condition in the startup.  You'll want to add a notification that the application is in Demo mode.

    Monday, January 11, 2021 12:58 PM
  • User-474980206 posted

    See any example of multi-tenant sites and databases.

    Monday, January 11, 2021 3:37 PM
  • User812858302 posted

    Yes i m trying to create the same scenarios u suggested but I  am not able to figure out how to pass if else condition in startup after demo link is clicked

    Wednesday, January 13, 2021 6:12 AM
  • User475983607 posted

    Yes i m trying to create the same scenarios u suggested but I  am not able to figure out how to pass if else condition in startup after demo link is clicked

    You misunderstand.  My suggestion is to change the entire approach.  The startup file runs well before a demo link is clicked so you can't have both approaches.

      

    Wednesday, January 13, 2021 12:02 PM
  • User-474980206 posted

    you don't handle in startup. its only called once. you inject a dbcontext factory not dbcontext. you can store demo state as a cookie,  part of the url or as an alternate host header (simplest if you only have two modes). use middleware to update a DI object with the current mode. alternative use a transient dbcontext accessor object and have middleware update with the correct dbcontext.

    google asp.net core multi-tenant for several ideas.  

    Wednesday, January 13, 2021 5:12 PM