2

I am kinda new at Asp.net and I have been trying to create a simple Transaction based system wherein users with different roles will have different menus and categories available for them. Currently, I am using this tutorial for my authenticated based login.

The code is working but I have noticed that the database being used is the default connection. What I wanted to do was create my own database and use it as the default connection (MyOwnConnectionString). How can I do that?

I am using VS 2015 and Sql Server 2016. I have a two tables namely Tbl_User and Tbl_Roles where the two tables are linked with the role_id

UPDATE

The tutorial above is about using the default registration of Asp.net wherein if the username to be used for registration matches the declared variable (in this case Admin), the user is given the role of Administrator in the Default Connection under tables AspNetUser, AspNetUserRoles, AspNetRoles.

I have a table named Tbl_User with columns "Name, Username, Password, Role"

Whenever I try to login, the database to be used is my created database(DB_Transaction) and not the default connect of Asp(DefaultConnection DB) and search for the corresponding roles in Tbl_Roles whether Admin or User then redirect them to their corresponding pages.

What should happen

2
  • This seems to be a broader topic. Could you break it down and try to ask separate questions ? You may also review this. Commented Nov 8, 2019 at 6:18
  • @MohanRadhakrishnan What I only wanted to know is how to implement the role based login using my created database in sql. I can't seem to find any tutorial that shows how to bind my database to the login. The two tables above is my tables for user and corresponding role. Based on the link I provided, the author uses the default login and database connection and created a class that whenever a user with Admin name is added, it is automatically registered as an Administrator. Roles is being implemented only during user registration. Commented Nov 8, 2019 at 6:29

4 Answers 4

1

If you want to use Asp.net Identity authentication and authorization then we need not to create table own self,the identity does it for us after user is registered. And login is handelled along with the authorization.Just specify the database name in ConnectionString and for now you can use DefaultConnection as ConnectionString Key.Add the register a dummy user.You should see tables in your specified database.

Sign up to request clarification or add additional context in comments.

5 Comments

Therefore I cannot use my own database for login? How unfortunate. Thanks for the information nonetheless
No , you could bind the tables somehow and use your own tables but that is very very difficult so I would suggest using default identity table to begin Asp.net.
Do you where I can learn that? Might as well try it. Additional knowledge for me I guess.
Not sure if there is an authentic tutorial for what you are looking for..but i could help as much as i can if you need.
Please. Teach me how to do it. I am really curious on how to do it.
0

Create database in SQL 2016 Add that connection string in WEB config file. After pass that connection string to your SQL Connection Object or Database Context for Entity framework.here is reference link

  <connectionStrings> 
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-WingtipToys;Integrated Security=True" providerName="System.Data.SqlClient" /> 
<add name="WingtipToys" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\wingtiptoys.mdf;Integrated Security=True" providerName="System.Data.SqlClient" /> 

2 Comments

Will I have two databases when I do this? Was planning on having only my local database to be used.
You can only use one data base right now either local or server. You have to decide which one is suitable for you.
0

you can change the default connection from web.config file open it an go to connection string and remove the default connection and copy your server name connection at SQL and paste in the connection string and u can change the database name as u can see in this image start remove the default connection from the local word enter image description here

enter image description here

this is the server name connection

1 Comment

Will this produce the default tables of Asp(AspNetRoles, AspNetUsers, AspNetUserRoles) in my database?
0

You can use the web.config file to update your connection string or use it in your code as well

using System.Data.SqlClient;

SqlConnection connection = new SqlConnection();
connection.ConnectionString ="Data Source=ServerName;" +"InitialCatalog=DataBaseName;" +
"Integrated Security=SSPI;";
connection.Open();

1 Comment

Just like with Sir Malak Naim suggestion, will this produce the default tables of Asp(AspNetRoles, AspNetUsers, AspNetUserRoles) in my database?

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.