.NET Framework Developer Center >
.NET Development Forums
>
ASMX Web Services and XML Serialization
>
How to prevent Cache and Form authentication from being reset
How to prevent Cache and Form authentication from being reset
What happens to Forms authentication and Cache (Context.Cache) when “web.config” file is modified?
How can i prevent them from resetting?
My webservice has to connect to different databases based upon user,How do i achieve this as i store ticket(user gets this upon login) in the cache and also use forms authentication.
gauls
Answers
- Using an external configuration file would solve your problem. Your main configuration file would reference this external config file. Modifying an external configuration file would not restart the application domain. Check the following MSDN link on details about how to implement.
http://msdn.microsoft.com/en-us/library/ms254494(VS.80).aspx- Marked As Answer byJohn SaundersMVP, ModeratorWednesday, July 08, 2009 2:22 PM
- Proposed As Answer byssaranv Tuesday, July 07, 2009 2:04 AM
All Replies
- When you change web.config, it forces an AppDomain reset. A new AppDomain is created and started, and all new requests are processed on the new AppDomain. Once all requests have completed on the old AppDomain, it is unloaded.
This is what is causing your problem, and this is how ASP.NET is designed. There is nothing you can do about it other than not modify web.config (or anything in the bin folder).
When using Cache, you should always be prepared to find that the cache entry you're looking for is null. In this case, you need to fetch a fresh copy of the data, and store it back into the cache.
John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of old ASMX or obsolete WSE
Use File->New Project to create Web Service Projects
- Proposed As Answer byMitchel SellersMVPMonday, July 06, 2009 7:37 PM
- Thanks for the quick replyWhat i am trying to achieve here is as followsMy webservice uses third party thick clients dll(gets the user info from them) and login into our database and returns a ticket for the user of the client, and for evey other calls to the webservice, a ticket is checked to authenticate the user.Now the above works fine if i install different webservices for each of the centrally located client(third party)application. Question is can i have just one installation of my webservice with multiple database(for each client this is where i need to change my web.config for connection string) for each of the third party(different versions)application ??many thanks
gauls - If I understand you correctly, you have three different database configuration strings that you use, one per client. Your web service is written to use one of the three at a time.
I would start off by duplicating the web service so there are three of them. Let each client connect to a different copy of the service. Each copy would have its own web.config, pointing to the correct database.
That's only a temporary fix. The goal would be to get the "duplicate" workaround working then, as soon as you can, working to train your service to know that there are three database connections, and to have it switch between them at runtime, depending on the client making the request.
John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of old ASMX or obsolete WSE
Use File->New Project to create Web Service Projects
- Using an external configuration file would solve your problem. Your main configuration file would reference this external config file. Modifying an external configuration file would not restart the application domain. Check the following MSDN link on details about how to implement.
http://msdn.microsoft.com/en-us/library/ms254494(VS.80).aspx- Marked As Answer byJohn SaundersMVP, ModeratorWednesday, July 08, 2009 2:22 PM
- Proposed As Answer byssaranv Tuesday, July 07, 2009 2:04 AM
- Hi SriSaran,That was an spot on answer , thanks a lot for the help guys
gauls- Unmarked As Answer byJohn SaundersMVP, ModeratorWednesday, July 08, 2009 2:22 PM
- Marked As Answer bygauls Tuesday, July 07, 2009 1:16 PM
- Thanks Gauls. It would be more helpful to mark this as an answer if this answers your question.
- Each call to Webservice has a login call first then getdata or savedata request from PDA client, Webservices uses thirdparty app to complete get and save data request. now if i want to install just one webservice which talks to 10 different thirparty app based on client's(PDA app) request (normally each PDA client talks to webservice which talks to its related third party app with database). What happens to current requests calls when new requests calls needs to talk to its own third party app ie it needs different connection string assuming i am using external config file to store different connection strings.first question is Is this possible ? Will there be a performance/speed issue?? and/ or any other problems??
In same senario above is it possible to install duplicate/multiple copies of same webservice with in the IIS? each of them handling its own PDA clients request if yes how ? what should be taken care while implementing it.
gauls - It depends entirely on how you go about it. If the request contains information on which database to use, then you could get the connection string from configuration, open a connection, execute commands, then close the connection. Connection pooling will make that less expensive than it sounds.
Otherwise, perhaps you could serve the same web service at different URLs. The clients would each have to call the service at the URL that corresponded to the database you want. In the service, looking at the URL would tell the service which database to use, just as though the client had passed a parameter saying which database to use.
John Saunders
WCF is Web Services. They are not two separate things.
Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
Use File->New Project to create Web Service Projects
- I am worried about the speed/performance of web service, Are you saying i can create multiple virtual directories of the same web service? does that mean different URL??
gauls


