How to create a System.Web.UI.Page object in a winform application?
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 sessi开发者_StackOverflow社区on state, but all are not affected.
So, can anybody tell me how to solve this case?
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
精彩评论