asp.net - How to create a PageStatePersister object that saves view and control state on the Web server -


reading book managed create class used base class override load , save methods extract , save view state information server. in book author suggests going following link , viewing example following:

instead of using page base class, use page adapter. modify functionality of pages without having change base classes. that's great if want store viewstate on server pages. find out how store viewstate pages using getstatepersister method of pageadapter class, visit:

all trying find way save viewstate without manually changing base class on each page.

i following error:

[argumentnullexception: value cannot null. parameter name: stream]    system.io.streamwriter..ctor(stream stream, encoding encoding, int32 buffersize, boolean leaveopen) +10409245    system.io.streamwriter..ctor(stream stream) +30    dev.streampagestatepersister.save() in a:\project\application\web\dev\streampagestatepersister.cs:57    system.web.ui.page.savepagestatetopersistencemedium(object state) +108    system.web.ui.page.saveallstate() +659    system.web.ui.page.processrequestmain(boolean includestagesbeforeasyncpoint, boolean includestagesafterasyncpoint) +1225 

here link referenced this:

http://msdn.microsoft.com/en-us/library/system.web.ui.pagestatepersister.aspx

streampagestatepersister.cs code

namespace dev {      using system;     using system.io;     using system.security.permissions;     using system.web;     using system.web.ui;      [aspnethostingpermission(securityaction.demand, level = aspnethostingpermissionlevel.minimal)]     public class streampagestatepersister : pagestatepersister     {          public streampagestatepersister(page page)             : base(page)         {         }          public override void load()         {             stream statestream = getsecurestream();              streamreader reader = new streamreader(statestream);              istateformatter formatter = this.stateformatter;             string filecontents = reader.readtoend();              pair statepair = (pair)formatter.deserialize(filecontents);              viewstate = statepair.first;             controlstate = statepair.second;             reader.close();             statestream.close();         }          public override void save()         {              if (viewstate != null || controlstate != null)             {                 if (page.session != null)                 {                     stream statestream = getsecurestream();                      streamwriter writer = new streamwriter(statestream);                      istateformatter formatter = this.stateformatter;                     pair statepair = new pair(viewstate, controlstate);                      // serialize statepair object string.                      string serializedstate = formatter.serialize(statepair);                      writer.write(serializedstate);                     writer.close();                     statestream.close();                 }                 else                     throw new invalidoperationexception("session needed streampagestatepersister.");             }         }         // return secure stream environment.          private stream getsecurestream()         {             // must provide implementation build              // secure stream environment.              return null;         }     } } 

mypageadapter.cs code

namespace dev {       using system.security.permissions;      using system.web;      using system.web.ui;       [aspnethostingpermission(securityaction.demand, level = aspnethostingpermissionlevel.minimal)]     public class mypageadapter : system.web.ui.adapters.pageadapter     {          public override pagestatepersister getstatepersister()         {             return new dev.streampagestatepersister(page);          } } } 

finally in browser file:

<browsers>     <browser id="newbrowser" parentid="mozilla">         <identification>             <useragent match="unique user agent regular expression" />         </identification>          <capture>             <useragent match="newbrowser (?'version'\d+\.\d+)" />         </capture>          <capabilities>             <capability name="browser" value="my new browser" />             <capability name="version" value="${version}" />         </capabilities>     </browser>      <browser refid="mozilla">         <capabilities>             <capability name="xml" value="true" />         </capabilities>        <controladapters>         <adapter             controltype="system.web.ui.page"             adaptertype="dev.mypageadapter" />       </controladapters>     </browser>   </browsers> 

i think should determine adapter rest of browsers. u try:

adaptertype="samples.aspnet.cs.mypageadapter" />


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -