I want to assigned new registered users automatically the role of Member in Database.
How can I assigned roles automatically in webmatrix
233 views Asked by user3607113 At
2
There are 2 answers
0
Skillet
On
WebMatrix sample Starter Site app - Account\Register.cshtml
Tested and it works.
// Check if user already exists
var user = db.QuerySingle("SELECT Email FROM UserProfile WHERE LOWER(Email) = LOWER(@0)", email);
if (user == null) {
// Insert email into the profile table
db.Execute("INSERT INTO UserProfile (Email) VALUES (@0)", email);
//Roles have already been added to webpages_Roles table
//Logic to determine role for e-mail (user) being added for the first time
if (email == "[email protected]") {
var userName=email;
var roleName="Administrator";
Roles.AddUserToRole(userName, roleName);
}
else if (email == "[email protected]") {
var userName=email;
var roleName="Guest";
Roles.AddUserToRole(userName, roleName);
}
else {
//All others are assigned the role of Member
var username=email;
var roleName="Member";
Roles.AddUserToRole(userName, roleName);
}
Related Questions in DATABASE
- How to add the dynamic new rows from my registration form in my database?
- How to store a date/time in sqlite (or something similar to a date)
- Problem with add new attribute in table with BOTO3 on python
- When an E-R attribute should be perceived as a relationship attribute or as an entity set attribute?
- SQLAlchemy: efficient relationship loading in 3-way many-to-many relationship
- Cannot connect to Postgres Database when running Quarkus Tests with Gitlab ci
- Local or remote database with react-native?
- I want to edit a specific row in database
- How to enter data in mongodb array at specific position such that if there is only 2 data in array and I want to insert at 5, then rest data is null
- Open Web Library
- database login.py and register.py error showing 404 file not found and doesn't work
- SQL71561: SqlComputedColumn: When column selected
- Liquibase as SaaS To Configure Multiple Database as Dynamic
- Updated max input vars but table still shows error
- Spring does not map set of roles
Related Questions in WEBMATRIX
- Why am I getting an error when adding namespace (using WebMatrix.WebData;) in ASP.NET MVC 5?
- Two table inserts retaining same ID for a ForeignKey using Webmatrix, Bootstrap, Html, and SQL
- IIS rewrite URL in asp.net goes to into infinity loop
- ActiveDirectoryMembershipProvider on Azure App Service: Access Denied
- What security does WebMatrix.WebData use
- Running local website site from Google File Stream. 404 for image and css files. IIS Express
- Get authentication from parent web application using webmatrix from MVC Core app
- Add input fields and validate the sum against total using javascript
- Up and Running with Webmatrix
- Accessing IIS Express from another machine
- WebMatrix Alternative for SqlCommand.Parameters.Add
- Attempt by method '[...].SimpleMembershipProvider.ConnectToDatabase()' to access method '[...].DatabaseConnectionInfo.Connect()' failed
- C# - Use WebImage.GetImageFromRequest() with multiple uploads
- How to get the values of radio buttons' values that where assigned with a variable to store in a data base using Razor
- Webmatrix QueryValue call raising SQLException "Incorrect syntax near '0'."
Related Questions in ROLES
- Troubleshooting object instantiation based on role in PHP app
- Ansible role variable is not defined
- Hierarchical roles for a user, with child roles having different permissions on case based, Laravel Spatie
- how to use two roles as a and operator in cerbos
- Approach to display links by role
- react router dom and role based
- How to add roles to a member using role id using discord.py?
- Can maintainers see my activity on Gitlab? Which roles are able to do this?
- Excluding a table from a Oracle role
- liferay, how to add a new permission to liferay using admin panel portal
- Laravel authorize for users and roles
- C# app service service principal role based authorization
- What roles does a postgresql database make use of?
- MSAL: Blazor Server client with AspNetCore API. Both protected by MSAL. How to have client access user's API roles?
- Accessibility role for button that links out of the app in Jetpack Compose
Related Questions in RESOLVE
- Ansible "Failed to resolve hostname inventory_hostname (Name or service not known)"
- JS Promise intended to resolve or reject randomly, displays 'undefined' in then/catch for the random value passed as argument in resolve/reject
- How to put a js promise inside a function that resolves the promise?
- React icons are not resolved
- module 'tkintermapview' not found error in python
- Cannot resolve native module with ElectronJS
- npm: could not resolve dependency tree (conflict)
- exported video have flicker in Davinci Reslove
- Django errors Found
- How does self attention help in deciding references
- Cannot resolve wildcard DNS with Resolve-DnsName : DNS_ERROR_INVALID_NAME_CHAR,Microsoft.DnsClient.Commands.ResolveDnsName
- How to increment a value in async function
- Reverse DNS lookup NodeJS
- Options rotate in /etc/resolv.conf is not working for kubernetes pods
- Android Studio cannot resolve symbols
Related Questions in WEBMATRIX-2
- How to convert request querystring to HMACSHA256 in webmatrix
- WebMatrix.WebData can't read membership information from a separate ASP.NET application
- How to use Windows Authentication in html in default.aspx
- Parameter Placeholders are causing an error in Webmatrix
- How to create Transaction Commit and Rollback in Webmatrix.Data.Database
- How can i get a specific version from the TFS using Web Matrix?
- Razor View Reference Error: FileNotFoundException
- Login failed for user 'sa'. WebSecurity.InitializeDatabaseConnection
- refresh div content in Microsoft webmatrix
- Is there TLS setting on webmatrix?
- Keep input data after posting
- How to handle a multi-site environment
- How does **WebSecurity.CreateUserAndAccount()** checks that username is already present in database?
- remote connection string from Webmatrix 3 to Microsoft SQL Server
- No WebSecurity.GetAllUsers() method. Why?
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
In your register code, which in the sample WebMatrix app is found in the file Account\Register.cshtml, there's if statements that first determine that the information being submitted is valid and then that the email doesn't exist in your database. Within those if statements, if the user is successfully created, then you can add code like:
Now I used 8 as an example. Look in your webpages_Roles table. This has a list of RoleNames and their RoleID. If you've already created the Member role, it will be in this table. Use the corresponding RoleID instead of the 8 that I used.