Multiple Web.Config files in ASP.NET web applicati

2019-02-19 13:37发布

问题:

I have an ASP.NET web application where i am having multiple subrirectories in the root folder.in my root web.config, i have sessionMode as "StateServer" . So in one page of my subdirectory, i am not able to do serialization. If i change the SessionMode method to "InProc" , it will work fine. I want to maintain the web.config file in the root directory as it is.So i am planning about having another web.config file in sub directory.Can anyone tell me how to do this ?

Thanks in advance

回答1:

You can just place a new web.config file in the sub-directory and ASP.NET will override any settings you change in that directory.



回答2:

While you can have a Web.config in every subdirectory not all settings are allowed at all levels.

And SessionMode is one setting that can only be made in the application-root.



回答3:

If you mark the class that is being put in the Session with the [Serializable] attribute, it can usually be used in an StateServer setup.



回答4:

Just put another web.config in the subdirectory. ASP.NET allows for that, and I have several areas on my website where the web.config contains values specifically for that "application" specifically.

That said:

1) Are you sure it's a good idea to maintain state in two different ways? It would probably be better to figure out how to make your session state serializable or get rid of using session state altogether.

2) All those web.config files can get tough to maintain if you're not careful about what values you put in each.