Add user manually
Hi,
i am trying to get a project going on my SQL Express, but it cannot find the server at config time. So I change the connection string after. It then creates all teh tables but asks me to login before asking me to create a user first. How do i get to add a user in the newly created database? i remember someone from telerik saying that you just delete the config files, i did that and it did not work.
many thanks,
andrei
Hello Andrei,
Let me elaborate a bit on the what exactly happens when a Sitefinity project is being created. At first, when you click on Create new project, main project files are created. If you then explore the project, you'll see for yourself that its folder contains nothing more than the application and few additional files needed for running the project in Visual Studio. At this step the only existing configuration file is the ProjectConfig, which contains basic information about the project. Right after that you are asked to setup the data configuration, which is done by opening the project in a browser and filling up the required fields. As far as I understand, on this step you didn't choose SQLExpress as a server, which means that your database has been created in the folder system of the other server you chose to use. This is actually one of the differences between SQLExpress and Microsoft SQL server, which I wanted to note. When you're using SQL Express the database is created in the App_Data folder, not the server directory. So this means that if you have a project, which was initially configured to use Microsoft SQL server and you want to move ti to SQLExpress, you need to move the database in the App_Data directory and change the data source in the connection string. Here's a connection string of a project that is on SQLExpress:
<
connectionStrings
>
<
add
connectionString
=
"Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|Sitefinity.mdf"
providerName
=
"System.Data.SqlClient"
dbType
=
"MsSql"
name
=
"Sitefinity"
/>
</
connectionStrings
>
var userManager = UserManager.GetManager(
"Default"
);
System.Web.Security.MembershipCreateStatus status;
userManager.Provider.SuppressSecurityChecks =
true
;
var user = userManager.CreateUser(
"user1"
,
"user1234@"
,
"user1@test.com"
,
"Question"
,
"Answer"
,
true
,
null
,
out
status);
user.FirstName =
"FirstName"
;
user.LastName =
"LastName"
;
userManager.SaveChanges();
RoleManager roleManager = RoleManager.GetManager(
"AppRoles"
);
roleManager.Provider.SuppressSecurityChecks =
true
;
var role = roleManager.GetRole(
"Administrators"
);
roleManager.AddUserToRole(user, role);
roleManager.SaveChanges();
Jen,
I finally managed to get it working on the Express Server without the need to attach the database. Please dont ask me how I got it working, because I would not be able to tell you. Many thanks for your very useful answer as well, it helped much. What I need to get sorted now is the TemplateImporter as I have mentioned in the other thread. The link you provided was broken, so if you could give me a screen-shot of exactly what I need to enter in which field, then I should be able to finally get it going.
Many thanks,
Andrei
Hello Andrei,
Excuse me for providing a broken link. It's fixed now. For your convenience I'm posting it here as well - Template Importer. Here's a screenshot with the required fields in the registration form for the Template Importer.
All the best,
Jen Peleva
the Telerik team
Jen
Thank you very much. The screen-shot helped to get it working. I am now able to successfully upload templates.
Many thanks again,
Andrei
Jen
The code you supplied was just what i need for my project. It worked initially but now i keep getting the following error;
Value cannot be null.
Description: An unhandled exception occurred during
the execution of the current web request. Please review the stack trace
for more information about the error and where it originated in the
code.
Parameter name: role
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: role
The code i am using is as follows;
RoleManager roleManager = RoleManager.GetManager();
roleManager.Provider.SuppressSecurityChecks = true;
var userRole = roleManager.GetRole("user");
roleManager.AddUserToRole(user, userRole);
roleManager.SaveChanges();
and the role of 'user' has been created in the sitefinity backend.
Any thoughts on where i have gone wrong?
Thanks
Jen
The code you supplied was just what i need for my project. It worked initially but now i keep getting the following error;
Value cannot be null.
Description: An unhandled exception occurred during
the execution of the current web request. Please review the stack trace
for more information about the error and where it originated in the
code.
Parameter name: role
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: role
The code i am using is as follows;
RoleManager roleManager = RoleManager.GetManager();
roleManager.Provider.SuppressSecurityChecks = true;
var userRole = roleManager.GetRole("user");
roleManager.AddUserToRole(user, userRole);
roleManager.SaveChanges();
and the role of 'user' has been created in the sitefinity backend.
Any thoughts on where i have gone wrong?
Thanks
Problem solved! The code works fine the project just wasn't compiling properly
(sorry for posting twice wasn't intentional)