More in this section

Forums / General Discussions / Add user manually

Add user manually

8 posts, 1 answered
  1. Andrei
    Andrei avatar
    24 posts
    Registered:
    22 Jan 2011
    10 Dec 2011
    Link to this post
    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
  2. Jen Peleva
    Jen Peleva avatar
    568 posts
    Registered:
    10 Nov 2016
    14 Dec 2011
    Link to this post
    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>
    Also, can you provide a little more information on your scenario. What do you mean by: "cannot find the server at config time."?
     You mentioned that you deleted the config files. If you do that, when running the project in browser you will be asked to setup the data config again, which will allow you to choose SQLExpress as a server, but you will also be required to create a new database. Does this suit your scenario?

    As for creating a new user with the role of an administrator, you can do that from the code behind of an aspx page. Take a look at the following code sample:

    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();


    Kind regards,
    Jen Peleva
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Andrei
    Andrei avatar
    24 posts
    Registered:
    22 Jan 2011
    15 Dec 2011
    Link to this post
    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
  4. Jen Peleva
    Jen Peleva avatar
    568 posts
    Registered:
    10 Nov 2016
    16 Dec 2011
    Link to this post
    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
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  5. Andrei
    Andrei avatar
    24 posts
    Registered:
    22 Jan 2011
    16 Dec 2011
    Link to this post
    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
  6. Dan
    Dan avatar
    15 posts
    Registered:
    19 Dec 2011
    09 Mar 2012
    Link to this post
    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.
    Parameter name: role

    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.

    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
  7. Dan
    Dan avatar
    15 posts
    Registered:
    19 Dec 2011
    09 Mar 2012
    Link to this post
    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.
    Parameter name: role

    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.

    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
  8. Dan
    Dan avatar
    15 posts
    Registered:
    19 Dec 2011
    09 Mar 2012
    Link to this post
    Problem solved! The code works fine the project just wasn't compiling properly
    (sorry for posting twice wasn't intentional)
8 posts, 1 answered