0

I have been following the tutorial here -

http://www.asp.net/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/create_the_data_access_layer

to build an ASP.NET web application.

What happens here is that

  • there all the member tables are under the "DefaultConnection" and
  • the user table is created under that connection.

However, all the other tables corresponding to the data layer are created in a separate database, called "wingtiptoys" and all the data related to the products of the toy store they happen to be making gets stored in tables there.

Because of this, I am finding it hard to exchange information between the tables in these two databases.

In an application of my own I'm working on, the tables actually have member information and I need to join those with the member table created by ASP.NET.

For that matter, I'm totally at a loss as to how the mechanism from the login page to the default users table works. I just find that there is a ASPNetUsers table in the Default database and it has the toy user information I used to login while testing my application but I couldn't find any place in the code for the login/register pages that tell them to store the user information in a table of that name.

In short, how to I create get the members table (the functionality for which ASP.NET provided by default) which is in the default DB to interact with the products and other tables which are in a separate DB created for the data layer of the application.

One option is to create a members table in the latter and ETL the data from the default DB to the members table some how. However, this seems inefficient.

Also, is there a default method to access the id of the currently logged in user?

0

1 Answer 1

1

To answer your first question: you will just have to utilize different instances of DbContext (ApplicationDbContext, and whatever you named the DbContext for "wingtiptoys") together.

For your second question: in the context of a Controller, the user's username can be found with System.Web.HttpContext.User.Identity.Name. In a Model, you'll have to use System.Web.HttpContext.Current.User.Identity.Name. Given the user's username, it should be trivial to find the UserId:

db.Users.Single(m => m.Username == User.Identity.Name).Id;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.