The issue I get is "The type initializer for 'umbraco.BusinessLogic.UserType' threw an exception" and no other useful information to help me track down the issue.
Searches through Google and this forum have all come up blank.
I'm really just testing at this point, but I'm running a web application that on the click of a button, sets off the method NewRegistration.
The line that fails is the first line of the method CreateUserType.
Code is:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using umbraco.cms.businesslogic.web; using umbraco.BusinessLogic;
namespace UmbracoLink { public class UmbracoLink {
#region Public methods
public void NewRegistration(String SiteName, String Username, String Password) { UserType userType = CreateUserType(SiteName); // User user = CreateUser(userType, SiteName, Username, Password); // Int64 siteId = CreateSite(SiteName, user); }
private User CreateUser(UserType UserType, String SiteName, String Username, String Password) { //set the right user type ID (available in usertype tree in the backend) User.MakeNew(SiteName + "Admin", Username, Password, UserType);
//Get the user from ID or login User u = new User(Username);
//Allow access to umbraco section u.addApplication("settings"); u.Save(); return u; }
private Int64 CreateSite(String SiteName, User User) { //Get the type you would like to use by its alias //and the user who should be the creator of the document DocumentType dt = DocumentType.GetByAlias("Textpage");
//create a document with a name, a type, an umbraco user, and the ID of the document's parent page. //To create a document at the root of umbraco, use the id -1 Document doc = Document.MakeNew("My new document", dt, User, -1);
//after creating the document, prepare it for publishing doc.Publish(User);
//Tell umbraco to publish the document umbraco.library.UpdateDocumentCache(doc.Id); return doc.Id; }
So far I've installed the product using the MS Web Platform Installer, configured it and created a few sample templates, stylesheets, content, etc using the UI.
Then I went straight into creating the .NET project and class that's above.
var newgroup =umbraco.BusinessLogic.UserType.MakeNew("MynewGroup", "PD", "newgroup"); var user = umbraco.BusinessLogic.User.MakeNew(CreateUserWizard1.UserName.ToString(), CreateUserWizard1.UserName, CreateUserWizard1.Password, newgroup); user.Save(); }
Difficulties with UserType.MakeNew
Hi,
Apologies if this isn't in the write forum - I couldn't decide between here and the our.dev section - but I'm having difficulties with the UserType.MakeNew function, even after copying the exact code from http://our.umbraco.org/wiki/reference/api-cheatsheet/users,-user-types-and-permissions.
The issue I get is "The type initializer for 'umbraco.BusinessLogic.UserType' threw an exception" and no other useful information to help me track down the issue.
Searches through Google and this forum have all come up blank.
Can anyone help?
Thanks
Rich
Are you trying to do this from a web application or from outside a web application (ie - a console application)?
Can you provide all your code?
PS: This is the right forum, the our.dev is for questions about the forum itself :)
Thanks slace.
I'm really just testing at this point, but I'm running a web application that on the click of a button, sets off the method NewRegistration.
The line that fails is the first line of the method CreateUserType.
Code is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using umbraco.cms.businesslogic.web;
using umbraco.BusinessLogic;
namespace UmbracoLink
{
public class UmbracoLink
{
#region Public methods
public void NewRegistration(String SiteName, String Username, String Password)
{
UserType userType = CreateUserType(SiteName);
// User user = CreateUser(userType, SiteName, Username, Password);
// Int64 siteId = CreateSite(SiteName, user);
}
#endregion
#region Private methods
private UserType CreateUserType(String SiteName)
{
UserType ut = UserType.MakeNew(SiteName + "Admins", "CAD", SiteName.ToLower() + "-admins");
ut.Save();
return ut;
}
private User CreateUser(UserType UserType, String SiteName, String Username, String Password)
{
//set the right user type ID (available in usertype tree in the backend)
User.MakeNew(SiteName + "Admin", Username, Password, UserType);
//Get the user from ID or login
User u = new User(Username);
//Allow access to umbraco section
u.addApplication("settings");
u.Save();
return u;
}
private Int64 CreateSite(String SiteName, User User)
{
//Get the type you would like to use by its alias
//and the user who should be the creator of the document
DocumentType dt = DocumentType.GetByAlias("Textpage");
//create a document with a name, a type, an umbraco user, and the ID of the document's parent page.
//To create a document at the root of umbraco, use the id -1
Document doc = Document.MakeNew("My new document", dt, User, -1);
//after creating the document, prepare it for publishing
doc.Publish(User);
//Tell umbraco to publish the document
umbraco.library.UpdateDocumentCache(doc.Id);
return doc.Id;
}
#endregion
}
}
Hi Richard,
Have you configured the data adapters within the web.config?
Sincere regards,
Eduardo
Hi Eduardo,
Where would I find instructions about that?
So far I've installed the product using the MS Web Platform Installer, configured it and created a few sample templates, stylesheets, content, etc using the UI.
Then I went straight into creating the .NET project and class that's above.
Hi Richard,
Why do you want to create the groups dinamically? I prefer creating groups through Umbraco BackEnd.
If you want to create members(frontend user accounts), use ASP.NET controls like createUserWizard:
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/login/createuserwizard.aspx
You can create members with createuserwizard and then, create an user for the backend. Here goes the example.
On the aspx or ascx page:
On the createduser event handler:
Web.Config example(it works):
For more information:
Follow the this link, you will find an interesting wiki article.
http://our.umbraco.org/forum/developers/api-questions/14567-Add-new-user-via-API
If you have any doubt let me know.
HTH.
Sincere regards,
Eduardo Macho
Thanks Eduardo,
I'll give that a shot.
is working on a reply...