views:

154

answers:

2

Hi all, I am using form base authentication in my Sharepoint site. On my login page there are custom fields to be filled by unauthenticated user. These fields i want to add in to my list. I am using following code to insert record in list.

protected void AddVendor(object sender, EventArgs e)
{
    string strList = "http://comp01:5353/Lists/Vendors/";

    using (SPSite site = new SPSite(strList))
    {
        site.AllowUnsafeUpdates = true;
        using (SPWeb web = site.OpenWeb())
        {
            web.AllowUnsafeUpdates = true;
            SPUser user = web.AllUsers["demouser"];    
            SPList list = web.Lists["Vendors"];
            SPListItem Item = list.Items.Add();
            Item["First Name"] = txtVendorName.Text;
            Item["Last Name"] = txtVLastName.Text;
            Item["business"] = txtDescription.Text;
            Item["Description"] = txtDescription.Text;
            Item["Mobile No"] = txtMobileNumber.Text;
            Item["Approved"] = "No";
            Item["Created By"] = "demoadmin";
            Item["Modified By"] = "demoadmin";   
            Item.Update();

        }
    }

}

but is is giving me an error saying that Thread was being aborted. I don't know what exactly missing. but is it because i am performing add action and user is not authenticated...?

A: 

Where have you written this code, is it inside some event ? Login Control Provides two events that will help you to solve this

OnLoginError="OnLoginError" OnLoggedIn="OnLoggedIn"

I did similar functionality where I wanted to capture the user name loggin to the site and log it to the DB Table. And with respect to the ThreadAbort Exception, it happens when you use Response.Redirect while a code is being executed. In you case I doubt that its being thrown because you are trying to do the above code but the FBA system tries to redirect the user to the default.aspx . Try out above said Event of the Login Control it should help you.

Kusek
A: 

I don´t know if it will help you but the code that says (f.e.) Item["Modified By"] will not work since that is the internal name which is *Modified_x0020_By*. This goes for all the fields with "spaces" in them.

This might be one of your issues...

Johan Leino