Answered by:
Need to have common identity DB for web app and web API

Question
-
User1835170460 posted
I have a solution where one project is a web application and another is a web API application. I am using ASP Identity and I need the registered users to be in one place common to both apps. I find that the web site works fine, I can create users and login. However when I try to create users via the web api (from a windows form app) it gives me an Internal Server Error. I know the problem is the web API can not access the DB. How can I direct it to use the DB of the web site?
Tuesday, November 10, 2015 5:45 PM
Answers
-
User1835170460 posted
I finally resolved the problem. My WebAPI project had a reference to the Web App and I moved things around and removed te reference and the problem disappeared. Everything works as it is supposed.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, November 12, 2015 3:09 PM
All replies
-
User-219423983 posted
Hi LuisCarlos,
I know the problem is the web API can not access the DB. How can I direct it to use the DB of the web site?
When you debug your code, do you make sure the error is about the database connection? As you want to use the common database, you could have a look at the following link that shows how to using an existing database in web api. I suggest you could use try-catch to catch the exception message to find out why the web api happen error.
I hope it’s useful to you.
Best Regards,
Weibo Zhang
Tuesday, November 10, 2015 8:48 PM -
User1835170460 posted
Hi Weibo, thanks for replying. I don't find in your post anything that would help in my case.
I decided to change the defaultconnection on both the web app and web api to my own DB and found that the web app now uses my DB to store users. However, the web API still will not work when I try to register users from a Windows Console app that I have for testing. I tried an experiment creating a separate solution with only a web api. Then when I run my console app against it it is able to create users. This leads me to the conclusion that the web api application can not be run concurrently with the web app. Any thoughts?
Wednesday, November 11, 2015 12:52 PM -
User-219423983 posted
Hi LuisCarlos,
What I want to show you by providing the above link is how to build a Web API based on an existing database. In your case, the web API use a common database, so I think the link would help just according to your original description.
For your latest response, I know your web API project and the web application are in a same solution. About the issue, do you debug your code when creating users? Does the issue is related to the database connection? Maybe the web API server is not running at that time?. Or, could you provide some error message?
I hope it’s useful to you.
Best Regards,
Weibo Zhang
Thursday, November 12, 2015 1:01 AM -
User1835170460 posted
I finally resolved the problem. My WebAPI project had a reference to the Web App and I moved things around and removed te reference and the problem disappeared. Everything works as it is supposed.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, November 12, 2015 3:09 PM