1

I'm not sure if this question is more SharePoint or more ASP.NET related.

In one of my lists I'm using .aspx page to create custom form for edit and create.

List schema.xml:

        <XmlDocuments>
      <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
        <FormUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
          <Edit>_layouts/UI/Pages/AddNewOrder.aspx</Edit>
          <New>_layouts/UI/Pages/AddNewOrder.aspx</New>
          <Display>_layouts/UI/Pages/AddNewOrder.aspx</Display>
        </FormUrls>
      </XmlDocument>
    </XmlDocuments>

In the page I have a form with mostly asp.net controls and save button.

The problem occurs (!)Only in Internet Explorer which should be the manin web browser for the app. When posting data on Save button click I'm getting an error. Page_Load and SaveData_Click methods are not hit in debugger.

Error from ULS:

    System.FormatException: The input is not a valid Base-64 string as       it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.    
 at System.Convert.FromBase64_Decode(Char* startInputPtr, Int32 inputLength, Byte* startDestPtr, Int32 destLength)    
 at System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength)    
 at System.Convert.FromBase64String(String s)    
 at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString, Purpose purpose)    
 at System.Web.UI.Util.DeserializeWithAssert(IStateFormatter2 formatter, String serializedState, Purpose purpose)    
 at System.Web.UI.HiddenFieldPageStatePersister.Load()

Another error code:

Getting Error Message for Exception System.Web.HttpException (0x80004005): The state information is invalid for this page and might be corrupted. ---> System.Web.UI.ViewStateException: Invalid viewstate.
ViewState: /wEPBSpWU0tleTo5NjQ4MDM5Yi0yYmViLTQ2NzQtODVhNS1lMDAxY2U5NWJmZjBkEnDmRxbrx80pe9MDNY7mdWPwIR64GPbhC6mlH34wZL4=,/wEPBSpWU0tleTo5NjQ4MDM5Yi0yYmViLTQ2NzQtODVhNS1lMDAxY2U5NWJmZjBkEnDmRxbrx80pe9MDNY7mdWPwIR64GPbhC6mlH34wZL4= ---> 

The problem dissapears when I try Document Mode IE8 in Internet Explorer but this can cause other problems.

I already tried:

  • version IE10 and IE11
  • removing all controls and code from the .aspx page (left only the Save button) and the problem still persisted!
  • turning off ViewState - I guess i failed to do that (tried in IIS and for the page only) but this my also cause other issues?

This is my first post on sharePoint stackexchange. I really hope you guys can help because I'm really struggling with this one.

0

Well I managed to solve the problem occuring in IE.

It actually seems that it was something with ViewState. What exactly I'm not sure but changing Maximum Page State Field Length from defult -1 to 100 helped.

ViewState modifications can be done in IIS for test purposes.

If you want to have this in code you can create Feature with Event receiver for scope WebApplication to do this on Features activation.

I'm posting the sample code below.

    /// <summary> 
/// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
/// </summary>
/// <remarks>
/// The GUID attached to this class may be used during packaging and should not be modified.
/// </remarks>
[Guid("5d087a09-f0e6-44d8-b147-67785f9d5074")]
public class WebModificationsFeatureEventReceiver : SPFeatureReceiver
{
    private const string WebConfigModificationOwner = "Some Owner Name";

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
        AddWebConfigModification(webApp);
    }

    public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
    {
        SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
        RemoveWebConfigModification(webApp);
    }

    //public override void FeatureInstalled(SPFeatureReceiverProperties properties)
    //{
    //    //SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
    //    //EnableFeature(webApp);
    //}

    //public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
    //{
    //}

    //public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters)
    //{
    //}

    private static readonly SPWebConfigModification[] WebConfigModifications =
    {
            new SPWebConfigModification
            {
                Owner = WebConfigModificationOwner,
                Name = "maxPageStateFieldLength",
                Type = SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute,
                Path = "configuration/system.web/pages",
                Sequence = 4,
                Value = "100"
            }
    };

    private static void RemoveWebConfigModification(SPWebApplication webApp)
    {
        var webConfigModifications = webApp.WebConfigModifications.Where(elem => elem.Owner == WebConfigModificationOwner).ToList();
        foreach (SPWebConfigModification modification in webConfigModifications)
        {
            webApp.WebConfigModifications.Remove(modification);
        }
        webApp.Update();
        webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
    }

    private readonly Guid _currentFeatureGuid = new Guid("5d087a09-f0e6-44d8-b147-67785f9d5074");

    private void AddWebConfigModification(SPWebApplication webApp)
    {
        try
        {
            foreach (SPWebConfigModification modification in WebConfigModifications)
            {
               //log
                webApp.WebConfigModifications.Add(modification);
            }

            // Commit modification additions to the specified web application.
            webApp.Update();
            // Push modifications through the farm.
            webApp.WebService.ApplyWebConfigModifications();
        }
        catch (Exception ex)
        {
            //log
        }
    }

    private void EnableFeature(SPWebApplication webApp)
    {
        var feature = webApp.Features.SingleOrDefault(sf => sf.DefinitionId == _currentFeatureGuid);
        if (feature == null)
        {
            // Activate feature
            webApp.Features.Add(_currentFeatureGuid);
            webApp.Update();
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.