Adding New User programmatically in SharePoint 2010

I've built a new SharePoint 2010 Web Site. My authantication type is Claims Based Auth. As you know, we use groups,members to manage or add users/permissions in Site Settings. I want to know that if I can make it with programmaticly. I mean I want to add new page for ex Register.aspx and Login.aspx. I've done Login.aspx with a code:

bool status = SPClaimsUtility.AuthenticateFormsUser(Context.Request.UrlReferrer,
    TextBox1.Text, TextBox2.Text);

if (!status)
{
    Label1.Text = "Wrong Userid or Password";
}
else
{
    if (Context.Request.QueryString.Keys.Count > 1)
    {
        Response.Redirect(Context.Request.QueryString["Source"].ToString());
    } 
    else
    {
        Response.Redirect(Context.Request.QueryString["ReturnUrl"].ToString());
    }
}

In this page, user have 2 x TextBoxes and a button. He/She can enter username and password and then login. At this point, I need a page to make new registration. I googled it a bit, but cant find enough information. My question is How can I make .aspx page which can be use for new membership?


Solution 1:

This is bad: Response.Redirect(Context.Request.QueryString["Source"].ToString(). What if the user enters www.mysite.com/mysite?Source=**http://www.myrealbadvirus.com**?
Don't redirect directly to a query string.

Here some links to get you started:

  • Programmatically granting permissions to claims
  • SharePoint : Add group of users to the user collection programmatically
  • Create Forms Based Authentication (FBA) programmatically users in SharePoint 2010
  • Programmatically create user groups Sharepoint 2010