views:

22

answers:

1

I have a class which inherits from the System.Web.UI.Page class, like mysystem. When I try to create an instance of mysystem in a winform appplication it throws an HttpException:

Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration>\<system.web>\<httpModules> section in the application configuration.

I then googled this problem and try to enable the session state, but all are not affected.

So, can anybody tell me how to solve this case?

+1  A: 

Any class that inherits from System.Web.UI.Page will attempt to utilise parts of the asp.net runtime when it's instantiated, so when it's used in a winforms application, it just won't work.

If there are methods that you need inside this class from another DLL, I'd suggest refactoring them into a separate class as:

  • If you want to use them in a winforms app, they're almost certainly not specific to the page so should be shared anyway
  • There's no good reason to try and use the asp.net runtime (other than, perhaps, caching) inside a winforms application
Rob
thx Rob, it is really a good advice and i had fixed this problem,thanks a lot.
Chris Cheung
@Chris, if my answer helped you solve the issue, please accept it by clicking on the outline of a tick to the left of the answer =)
Rob