Results 1 to 11 of 11

Thread: Problems with ViewState

  1. #1

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Question Problems with ViewState

    I've finally managed to deploy my Asp.Net Webforms app...

    http://www.scproject.biz/numbers_game.php#playnow

    Occasionally, I'm getting a MAC error. The error points to this article...

    https://support.microsoft.com/en-gb/...ode-mac-errors

    I think the error relates to multiple users, but that's just a guess. Can anyone explain which of the solution steps would be best and how to implement it?

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Problems with ViewState

    Quote Originally Posted by .paul. View Post
    I've finally managed to deploy my Asp.Net Webforms app...

    http://www.scproject.biz/numbers_game.php#playnow

    Occasionally, I'm getting a MAC error. The error points to this article...

    https://support.microsoft.com/en-gb/...ode-mac-errors

    I think the error relates to multiple users, but that's just a guess. Can anyone explain which of the solution steps would be best and how to implement it?
    ???

    The article you linked to says nothing about multiple users. In fact, the word "multiple" never appears at all.

    The article outlines four potential causes of the error. No one here can tell you which of those four causes is in play since three of them require access to or knowledge of the web server configuration, and the 4th cause involves the potential use of the Page.ViewStateUserKey property in your code.

    Assuming you've ruled out #4, I'd send the first three to your hosting provider and ask them to respond back as far as if any of those are relevant to how their hosting environment is set up.

    Good luck.

  3. #3

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Problems with ViewState

    Ok. The app. worked in debug. How can i rule out the Page.ViewStateUserKey property?

  4. #4
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Problems with ViewState

    Are you using that property explicitly in your code? If not, then that isn't the cause.

  5. #5

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Problems with ViewState

    Quote Originally Posted by OptionBase1 View Post
    Are you using that property explicitly in your code? If not, then that isn't the cause.
    Ok thanks. I'll get on to my site's tech support... I'm seriously considering migrating to AWS. I'd hire a freelancer to help with that though.

  6. #6
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Problems with ViewState

    What is the error you are facing.
    Please mark you thread resolved using the Thread Tools as shown

  7. #7

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Problems with ViewState

    Quote Originally Posted by danasegarane View Post
    What is the error you are facing.
    This is the error...


    Server Error in '/' Application.
    Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

    See http://go.microsoft.com/fwlink/?LinkID=314055 for more information.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

    See http://go.microsoft.com/fwlink/?LinkID=314055 for more information.

    Source Error:

    The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

    1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

    <%@ Page Language="C#" Debug="true" %>

    or:

    2) Add the following section to the configuration file of your application:

    <configuration>
    <system.web>
    <compilation debug="true"/>
    </system.web>
    </configuration>

    Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

    Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

    Stack Trace:


    [ViewStateException: Invalid viewstate.
    Client IP: 89.243.236.168
    Port: 51598
    Referer: http://www.scproject.biz/Default.aspx
    Path: /Default.aspx
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36
    ViewState: /wEPDwUJMjc5MjQxMDA1D2QWAgIDD2QWCAIDD2QWAmYPZBYCAgEPDxYCHghJbWFnZVVybAUwaHR0cDovL3d3dy5zY3Byb2plY3QuY ml6L2Nsb2NrX2ltYWdlcy9mYWNlXzIucG5nZGQCCQ9kFgJmD2QWAgIBDw8WAh4EVGV4dAUDMjcwZGQCCw9kFgJmD2QWDAIBDw8WA h8BBQI3NWRkAgMPDxYCHwEFAjUwZGQCBQ8PFgIfAQUBOGRkAgcPDxYCHwEFATJkZAIJDw8WAh8BBQExZGQCCw8PFgIfAQUCMTBkZ AIVD2QWAmYPZBYCAgEPDxYCHwFlZGRkbNhYSmwVqDKnNh1XfSiJUUz5HlHjzqaWvxcvKd7Bu90=]

    [HttpException (0x80004005): Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

    See http://go.microsoft.com/fwlink/?LinkID=314055 for more information.]
    System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) +116
    System.Web.UI.ObjectStateFormatter.Deserialize(String inputString, Purpose purpose) +425
    System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter2.Deserialize(String serializedState, Purpose purpose) +13
    System.Web.UI.Util.DeserializeWithAssert(IStateFormatter2 formatter, String serializedState, Purpose purpose) +40
    System.Web.UI.HiddenFieldPageStatePersister.Load() +248
    System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +251
    System.Web.UI.Page.LoadAllState() +36
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6569
    System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +245
    System.Web.UI.Page.ProcessRequest() +72
    System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +22
    System.Web.UI.Page.ProcessRequest(HttpContext context) +58
    ASP.default_aspx.ProcessRequest(HttpContext context) +4
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +188
    System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +48
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +71

    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3535.0

  8. #8

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Problems with ViewState

    Setting a <machineKey> configuration in web.config could be the answer i'm looking for

  9. #9

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Problems with ViewState

    My web hosting company have decided this is a programming issue and they're refusing to help...

  10. #10

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Problems with ViewState

    I used Powershell to generate a <machinekey> that i put in my web.config file. It seems to have fixed the error. Thanks again...

  11. #11
    Lively Member
    Join Date
    Jan 2020
    Posts
    120

    Re: Problems with ViewState

    Hello,@.paul.

    Please follw this step,To Problems with ViewState

    Step 1

    Create an app.browser file in App_browsers directory. Plug in page adapters in the app.browser file as follows:

    File: App_browsers\app.browser
    Code:
    <browser refID="Default">
      <controlAdapters>
        <adapter controlType="System.Web.UI.Page"
                 adapterType="Alachisoft.NCache.Adapters.PageAdapter" />
        </controlAdapters>
    </browser>
    Step 2

    Add the following assembly reference in compilation section of web.config file.

    File: web.config

    Code:
    <compilation defaultLanguage="c#" 
                 debug="true" 
                 targetFramework="4.0">
      <assemblies> 
        <add assembly="Alachisoft.NCache.Adapters,
                       Version=1.0.0.0,
                       Culture=neutral,
                       PublicKeyToken=CFF5926ED6A53769"/>
      </assemblies>
    </compilation>
    Step 3

    Register NCache config section in your web.config file.

    File: web.config
    Code:
    <configSections>
      <sectionGroup name="ncContentOptimization">
        <section name="settings" 
                 type="Alachisoft.NCache.ContentOptimization.
                      Configurations.ContentSettings" 
                 allowLocation="true"
                 allowDefinition="Everywhere"/>
      </sectionGroup>
    </configSections>
    Step 4

    Specify settings for your config section in web.config file (that was registered above). These settings control NCache ASP.NET View State Caching features.

    File: web.config
    Code:
    <ncContentOptimization>
      <settings viewstateThreshold="12" 
                enableViewstateCaching="true" 
                enableTrace="false" 
                groupedViewStateWithSessions="false"
                maxViewStatesPerSession="3" >
          <cacheSettings cacheName="myCache">
            <expiration type="Absolute" 
                        duration="1" />
          </cacheSettings>
      </settings>
    </ncContentOptimization>
    Step 5

    In the end, register the HTTP handler in the HttpHandlers section of web.config as following:

    File: App_browsers\app.browser

    Code:
    <httphandlers>
      <add verb="GET,HEAD" 
           path="NCResource.axd" 
           validate="false" 
           type="Alachisoft.NCache.Adapters.ContentOptimization.ResourceHandler, 
                 Alachisoft.NCache.Adapters, Version=1.0.0.0, Culture=neutral, 
                 PublicKeyToken=cff5926ed6a53769"/>
    </httphandlers>
    I hope this information will be useful.
    Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width