Standalone webapi created For Authentication and Authorization using jwt token.
1. SqlServer 20192. Visual studio 2022 prefferd
Change data source in Web.config (line 12) "LAPTOP-NAIGAH36\SQLEXPRESS" with yours
1. Start debuging2. open postman->body->raw (Format shoould be json)
3. Method - POST Url - https://localhost:44310/api/Roleapi/createrole (Check your port once)
4. For creating admin role put
"Admin"
5. Send
6. Create "User" as well because its default registration role.
To check role created and users assgned to that role
Method - GET
Url - https://localhost:44310/api/Roleapi
2. put your desired parameter in Class Applicationuser
eg public string Name { get; set; }
3. Perform migration with following commands
- enable-migration
- add-migration Newmigration
- update-database
Models->AccountBindingModels.cs->Public Class RegisterBindingModel
as well as
Controller->Accountcontroller.cs->public async Task Register(RegisterBindingModel model)
1. Goto Postman
2. Method - POST Url - https://localhost:44310/api/Account/register
3. select x-www-form-urlencode
4. put all required values as key and value (username,name,email,password,confirmpassword)
eg key - username value - admin
To crate user as per various roles AccountController.cs->Register
and change UserManager.AddToRole(user.Id, "User"): accordingly.
2. Method - POST Url - https://localhost:44310/api/Account/login
3. select x-www-form-urlencode
4. put all required values as key and value
eg key - username value - admin
key - password value - Pass@123