locked
Multiple databases for authenticating web api2 RRS feed

  • Question

  • User1554713606 posted

    Hello,

    I have built a web api and using token based authentication for authenticating user. Till now the users where in the one database and we are going to use different second database for authentication. 

    Now Issue is I don't know how to authenticate using two different databases. Basically token has to be created from different databases.

    I tried changing dbcontext on runtime which I wasn't able to do for token generation.

    Any help will be really helpful.

    Thanks,

    Vivek

    Friday, September 22, 2017 11:35 PM

All replies

  • User1120430333 posted

    I tried changing dbcontext on runtime which I wasn't able to do for token generation.

    The context is for a specific DB,  and you can't share context across DB(s).

    Saturday, September 23, 2017 1:30 AM
  • User-271186128 posted

    Hi Vivek,

    vivek100

    Multiple databases for authenticating web api2

    You could try to add multiple dbcontext in the web API (using different connection string). Like this:

        public partial class SchoolContext : DbContext
        {
            public SchoolContext()
                : base("name=SchoolContext2") //the connection string name.
            {
            }

    Then, using different dbcontext to authenticate user.

    Best regards,
    Dillion

    Monday, September 25, 2017 6:37 AM