[CLOSED] Using ContentPlaceHolder will Makes "The state information is invalid for this page and might be corrupted" Exception

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Using ContentPlaceHolder will Makes "The state information is invalid for this page and might be corrupted" Exception

    Hello,

    I found when i use master.site to layout my page, <ContentPlaceHolder> will make page crash when i press some button to do DirectEvent.

    snapshot(The meaning of the exception is "The state information is invalid for this page and might be corrupted", ArgumentNullException cannot be null)
    Click image for larger version. 

Name:	2017-04-20 11_27_22-About - My ASP.NET Application.jpg 
Views:	94 
Size:	96.0 KB 
ID:	24917


    site.master
    <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="TestWebForm.SiteMaster" %>
    
    <!DOCTYPE html>
    
    <html lang="en">
    <head runat="server">
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title><%: Page.Title %> - My ASP.NET Application</title>
    
        <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ResourceManager runat="server"/>
            <ext:Viewport ID="Viewport1" runat="server" Layout="FitLayout">
                <Content>
                    <asp:ContentPlaceHolder ID="MainContent" runat="server" />
                </Content>
            </ext:Viewport>    
        </form>
        
    </body>
    </html>
    about.aspx
    <%@ Page Title="About" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="About.aspx.cs" Inherits="TestWebForm.About" %>
    
    <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
        <ext:GridPanel ID="gridOrg" runat="server" Title="医疗机构" ColumnLines="true" Height="200">
            <TopBar>
                <ext:Toolbar ID="GridOrgToolbar" runat="server">
                    <Items>
                        <ext:Button ID="BtnAdd" Text="新增" runat="server">
                            <DirectEvents>
                                <Click OnEvent="OnOrgCreate" />                                  
                            </DirectEvents>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </TopBar>
        </ext:GridPanel>
    </asp:Content>
    about.aspx.cs

    namespace TestWebForm {
        public partial class About : Page {
            protected void Page_Load(object sender, EventArgs e) {
    
            }
    
            protected void OnOrgCreate(object sender, DirectEventArgs e) {
                
            }
        }
    }
    Ted
    Last edited by fabricio.murta; Apr 27, 2017 at 2:55 AM.
  2. #2
    Hello Ted!

    I couldn't reproduce the issue by running your test case here. The button works just fine no matter how many times I click it.

    May I suggest you to try and create a clean project and solution, install Ext.NET on it from NuGet (either the public ones or the ones you can generate from sources), and test your code sample there?

    It seems it takes something else to reproduce the issue, and I am suspecting a setting in Web.config.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Fabricio,

    I were test under new, clean project. My Environment.

    Visual Studio 2015,
    Ext.NET 4.2

    web.config

    <?xml version="1.0" encoding="utf-8"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    <configuration>
      <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      <section name="extnet" type="Ext.Net.GlobalConfig" requirePermission="false" /></configSections>
      <connectionStrings>
        <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-TestWebForm-20170420105221.mdf;Initial Catalog=aspnet-TestWebForm-20170420105221;Integrated Security=True" providerName="System.Data.SqlClient" />
      </connectionStrings>
      <system.web>
        <authentication mode="None" />
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5" />
        <!-- This httpHandlers config only required if using IIS6 (or lower) --><!--
        <httpHandlers>
          <add path="*/ext.axd" verb="*" type="Ext.Net.ResourceHandler" validate="false" />
        </httpHandlers>
        --><!-- This httpModules config only required if using IIS6 (or lower) --><!--
        <httpModules>
          <add name="DirectRequestModule" type="Ext.Net.DirectRequestModule, Ext.Net" />
        </httpModules>
        --><pages>
          <namespaces>
            <add namespace="System.Web.Optimization" />
            <add namespace="Microsoft.AspNet.Identity" />
          <add namespace="Ext.Net" /></namespaces>
          <controls>
            <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
          <add assembly="Ext.Net" namespace="Ext.Net" tagPrefix="ext" /></controls>
        </pages>
        <membership>
          <providers>
            <!--
    	      ASP.NET Membership is disabled in this template. Please visit the following link http://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template
            -->
            <clear />
          </providers>
        </membership>
        <profile>
          <providers>
            <!--
    	      ASP.NET Membership Profile is disabled in this template. Please visit the following link http://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template
            -->
            <clear />
          </providers>
        </profile>
        <roleManager>
          <!--
    	        ASP.NET Membership Role is disabled in this template. Please visit the following link http://go.microsoft.com/fwlink/?LinkId=301889 to learn about the ASP.NET Membership support in this template
            -->
          <providers>
            <clear />
          </providers>
        </roleManager>
        <!--
                If you are deploying to a cloud environment that has multiple web server instances,
                you should change session state mode from "InProc" to "Custom". In addition,
                change the connection string named "DefaultConnection" to connect to an instance
                of SQL Server (including SQL Azure and SQL  Compact) instead of to SQL Server Express.
          -->
        <sessionState mode="InProc" customProvider="DefaultSessionProvider">
          <providers>
            <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
          </providers>
        </sessionState>
      </system.web>
      <system.webServer>
        <modules>
          <remove name="FormsAuthentication" />
        <add name="DirectRequestModule" preCondition="managedHandler" type="Ext.Net.DirectRequestModule, Ext.Net" /></modules>
      <validation validateIntegratedModeConfiguration="false" /><handlers>
          <add name="DirectRequestHandler" verb="*" path="*/ext.axd" preCondition="integratedMode" type="Ext.Net.ResourceHandler" />
        </handlers></system.webServer>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
            <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
            <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin" culture="neutral" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security.OAuth" culture="neutral" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security.Cookies" culture="neutral" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security" culture="neutral" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="mssqllocaldb" />
          </parameters>
        </defaultConnectionFactory>
        <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
      </entityFramework>
      <system.codedom>
        <compilers>
          <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
          <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
        </compilers>
      </system.codedom>
    <extnet theme="Triton" licenseKey="** Ext.NET LICENSE KEY HERE **" initScriptMode="Linked" /></configuration>
  4. #4
    Hello!

    I've retried also from a fresh project in VS2015 for no avail. The page works fine.

    I don't think it could be the case, but I'm running your sample slightly simplified here, can you try this approach on your side?

    Simply have these two files in the same directory. No code behind/designer files, you can delete those from the webforms page (or create the page as a plaintext file and rename its extension afterwards):

    61870-master.Master
    <%@ Master Language="C#" %>
    
    <!DOCTYPE html>
    
    <html lang="en">
    <head runat="server">
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title><%: Page.Title %> - My ASP.NET Application</title>
        <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ResourceManager runat="server"/>
            <ext:Viewport ID="Viewport1" runat="server" Layout="FitLayout">
                <Content>
                    <asp:ContentPlaceHolder ID="MainContent" runat="server" />
                </Content>
            </ext:Viewport>    
        </form>
    </body>
    </html>
    61870-contentPlaceHolderIssue.aspx
    <%@ Page Title="About" Language="C#" MasterPageFile="61870-master.Master" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e) {
        }
    
        protected void OnOrgCreate(object sender, DirectEventArgs e) {
        }
    </script>
    <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
        <ext:GridPanel ID="gridOrg" runat="server" Title="医疗机构" ColumnLines="true" Height="200">
            <TopBar>
                <ext:Toolbar ID="GridOrgToolbar" runat="server">
                    <Items>
                        <ext:Button ID="BtnAdd" Text="新增" runat="server">
                            <DirectEvents>
                                <Click OnEvent="OnOrgCreate" />                                  
                            </DirectEvents>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </TopBar>
        </ext:GridPanel>
    </asp:Content>
    The files can sit in any webforms-aware directory (like root), just should be in the same directory. I don't see a reason this set up should "make it work", but better being sure about it, as I also don't see why you are getting the error on your side as well.

    The error is deterministic, right? I mean, every time you click the "新增" button, the error is triggered.
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Fabricio,

    The error is deterministic. and i have created the 2 pages you mention under my testing solution and I got nothing but only the empty reponse "{}" when click the button on your page.

    here is the web console of 61870-contentPlaceHolderIssue:
    Click image for larger version. 

Name:	2017-04-24 10_11_34-Developer Tools - http___localhost_50183_61870-contentPlaceHolderIssue.png 
Views:	102 
Size:	97.0 KB 
ID:	24920


    and here is the snapshot of my page:
    Click image for larger version. 

Name:	2017-04-24 10_13_11-Developer Tools - http___localhost_50183_About.jpg 
Views:	78 
Size:	96.2 KB 
ID:	24921


    i also change MasterPageFile setting of my page to 61870-master.Master. I found i also got nothing same with the 61870-contentPlaceHolderIssue.aspx page.

    here is the snapshot of my modified page:
    Click image for larger version. 

Name:	2017-04-24 10_23_04-Developer Tools - http___localhost_50183_About_new.png 
Views:	74 
Size:	96.1 KB 
ID:	24922


    Any idea what's happened?
  6. #6
    Hello Ted!

    Well, it actually should return an empty response as the OnOrgCreate() event is but empty.

    Quote Originally Posted by u8621011
    The error is deterministic. and i have created the 2 pages you mention under my testing solution and I got nothing but only the empty reponse "{}" when click the button on your page.
    So then, it means that the example the way I provided, the 61870-contentPlaceHolderIssue.asxp and 61870-master.Master works for you?

    I didn't quite follow the screenshots you shared, what should I be looking for on them?

    Quote Originally Posted by u8621011
    i also change MasterPageFile setting of my page to 61870-master.Master. I found i also got nothing same with the 61870-contentPlaceHolderIssue.aspx page.
    So here, you say that you changed in the original example, the page to use the Master file in the same directory, and then it worked? You using "nothing" to refer to "nothing worked", or "nothing wrong" when you run the examples?
    Fabrício Murta
    Developer & Support Expert
  7. #7
    I didn't quite follow the screenshots you shared, what should I be looking for on them?
    I have shared 3 snapshots with you in previous post. I found form data has something diff.

    In my original aspx(that one causes HTTP 500). No "_VIEWSTAGEGENERATOR", but your and my MasterPageFile modified page both have that.

    Is that normal?


    So here, you say that you changed in the original example, the page to use the Master file in the same directory, and then it worked? You using "nothing" to refer to "nothing worked", or "nothing wrong" when you run the examples?
    My meaning is nothing wrong happended (also just return {} response), but my modified page have some codes in code behind.

    codes are:
    protected void OnOrgCreate(object sender, DirectEventArgs e) {
        X.Msg.Alert("System Msg", "hello");
    }

    Any idea about this bug? I have no more direction to figure it out.
  8. #8
    Hello Ted!

    Let me see if I could understand first:
    So, the problem is, if using /Site.Master you get the viewstate error and, if you use any other master page (in the same folder for example), it works just fine? The error is exactly by using the Site.Master instead of any other master page file?

    I just tested here creating a Site.Master on a clean project, then a "WebForms using Site.Master", and pointing it to the Site.Master file, and it worked just fine.

    By the way, you are not going to see anything from your OnOrgCreate event. You should also make the alert be actually shown, calling it as:

    X.Msg.Alert("System Msg", "hello").Show();
    How exactly did you create the Site.Master file on your project? Are you using it (by any chance) from a Template?

    I only could reproduce the issue on an old Site.Master from a WebForms template I had installed, but the master page had this code behind which tainted the ViewState (at least at the point of view that it would work with Ext.NET):

    Site.Master.cs:
    public partial class SiteMaster : MasterPage
    {
    private const string AntiXsrfTokenKey = "__AntiXsrfToken";
    private const string AntiXsrfUserNameKey = "__AntiXsrfUserName";
    private string _antiXsrfTokenValue;
    
    protected void Page_Init(object sender, EventArgs e)
    {
        // The code below helps to protect against XSRF attacks
        var requestCookie = Request.Cookies[AntiXsrfTokenKey];
        Guid requestCookieGuidValue;
        if (requestCookie != null && Guid.TryParse(requestCookie.Value, out requestCookieGuidValue))
        {
            // Use the Anti-XSRF token from the cookie
            _antiXsrfTokenValue = requestCookie.Value;
            Page.ViewStateUserKey = _antiXsrfTokenValue;
        }
        else
        {
            // Generate a new Anti-XSRF token and save to the cookie
            _antiXsrfTokenValue = Guid.NewGuid().ToString("N");
            Page.ViewStateUserKey = _antiXsrfTokenValue;
    
            var responseCookie = new HttpCookie(AntiXsrfTokenKey)
            {
                HttpOnly = true,
                Value = _antiXsrfTokenValue
            };
            if (FormsAuthentication.RequireSSL && Request.IsSecureConnection)
            {
                responseCookie.Secure = true;
            }
            Response.Cookies.Set(responseCookie);
        }
    
        Page.PreLoad += master_Page_PreLoad;
    }
    
    protected void master_Page_PreLoad(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // Set Anti-XSRF token
            ViewState[AntiXsrfTokenKey] = Page.ViewStateUserKey;
            ViewState[AntiXsrfUserNameKey] = Context.User.Identity.Name ?? String.Empty;
        }
        else
        {
            // Validate the Anti-XSRF token
            if ((string)ViewState[AntiXsrfTokenKey] != _antiXsrfTokenValue
                || (string)ViewState[AntiXsrfUserNameKey] != (Context.User.Identity.Name ?? String.Empty))
            {
                throw new InvalidOperationException("Validation of Anti-XSRF token failed.");
            }
        }
    }
    
    protected void Page_Load(object sender, EventArgs e)
    {
    
    }
    
    protected void Unnamed_LoggingOut(object sender, LoginCancelEventArgs e)
    {
        Context.GetOwinContext().Authentication.SignOut();
    }
    From the code above, I removed lines 5-56 (from 5 to 56) and also 65, rebuilt and the test page's click worked fine.

    But again, from a fresh project, with a clean master page, this didn't happen. I didn't see anything on your Web.config that could have tainted the ViewState either.

    Can you double check your project for anything that might be touching the viewstate? As the MasterPage I found here, it was fiddling with user login credentials on ViewState, which is not wrong, but I don't think it is related to your cause of the viewstate being corrupted. Well, at least it looks like something else is happening on your project to have the page broken if using that specific master page.
    Fabrício Murta
    Developer & Support Expert
  9. #9
    Fabricio,

    Ya, that is also my Site.Master.cs code, maybe that's where the viewstate error caused???


    Another question is,

    By the way, you are not going to see anything from your OnOrgCreate event. You should also make the alert be actually shown, calling it as:
    X.Msg.Alert("System Msg", "hello").Show();
    The server only reponse "{}" to me even I have the codes above in my code behind. Is it correct response?

    Ted
  10. #10
    Hello Ted!

    So yes, you have something else wrong. Please try with a clean project and Master page (no login or any viewstate related code).

    You should get the dialog saying 'hello' when you click the button. It worked here like a charm.

    As for the viewstate problem I believe you can just remove all that code from your master page and it will work fine. Then if you really need some of that code that breaks, provide us a test case with the minimal set of code that triggers the issue. If that's a bug, we'll log it as a bug and do our best to give you at least an workaround for the time being. If that's something you shouldn't be doing that way, we'll provide you with advice on how to deal with that to attain what you need.
    Fabrício Murta
    Developer & Support Expert
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 0
    Last Post: Jan 24, 2014, 4:57 PM
  2. Replies: 7
    Last Post: Dec 19, 2013, 7:16 PM
  3. <%@ Page Language="C#" Buffer="false" %>
    By zanotto in forum 2.x Help
    Replies: 2
    Last Post: Nov 21, 2013, 4:32 PM
  4. Replies: 2
    Last Post: Jun 26, 2011, 1:59 AM
  5. Replies: 1
    Last Post: Mar 13, 2011, 9:21 AM

Posting Permissions