问题
I didn't know how to title this question - I am making a request to PayPal's Express Payment API. I'm using their dll that helps make the request and parse the response. The instructions for their code to work is to add you authorization credentials in the web.config
file. I have done so. My problem is that I want to be able to edit these credentials that are being set dynamically (probably got from SQL) because we are going to allow different users to enter their API credentials. Sending the request to PayPal looks like this
Dim wrapper As New SetExpressCheckoutReq()
wrapper.SetExpressCheckoutRequest = request
Dim service As New PayPalAPIInterfaceServiceService()
Dim setECResponse As SetExpressCheckoutResponseType = service.SetExpressCheckout(wrapper)
There's not much room in there to edit the header of the request, because PayPalAPIInterfaceServiceService()
is defined in their dll and applies its own header based on the credentials in the web.config.
So, my question is, is there a way to point in the web.config
to another location when it looks in web.config
? I'm not to sure this is possible. Also, is there any way to edit the header of a request that is defined in a dll without changing the dll (to stay pci compliant)
Here is the line in the web.config:
<account apiUsername="****" apiPassword="****" apiSignature="****"/>
Edit:
I know it is bad to add or edit web.config dynamically , I was looking more for a way to point to another location that can be edited. Like in C# code you could write Settings["string"]
and that points into the web.config. Is there a way in the web.config to point to a location in the project , and this location could be changed dynamically
回答1:
I agree with iefpw that modifying a web.config file manually is bad news, but since you asked, WebConfigurationManager provides the functionality you are looking for.
That class has a Save method that can be called after you've made your changes. I've only used WebConfigurationManager for reading web.config files, so don't have a code example for you. Good luck.
回答2:
You have to do this dynamically from the SQL Server, setting credential everytime in the web config will mess up your system. Also web.config is for the whole application. Do straight dynamic sql query from the database and supply to paypal. Don't mess with web.config if you have multiple credentials.
来源:https://stackoverflow.com/questions/12985068/edit-settings-in-web-config