0

I have created a C# project. Now I want to save an IP address in the web.config file with the help of key and value.

<add key="ip" value="xxxx.xxx.x.xxx" />

Now I am able to read the value with the help of key name and also able to update the value of the key. It's running in localhost successfully.

But if I put the files in IIS I can read the value but can't update the key value. Error like this is showing in Mozilla Firebug. The error is as follows

NetworkError: 500 Internal Server Error

Access to the path \u0027C:\inetpub\wwwroot\Order1\v1y5ay43.tmp\u0027 is denied.

I stuck over here. I Google it but did not find any solution.

Community
  • 1
  • 1
Saikat
  • 410
  • 2
  • 9
  • 25
  • Are you trying to have your web app modify the config file? – Tim Apr 25 '13 at 05:57
  • yes Tim you are absolutely right. Actually client ip address will be save in web.config. And he can modify the ip address form the app. A form which has a textbox and a button should be provided to the client. – Saikat Apr 25 '13 at 06:02
  • Take a look at this answer for an example: http://stackoverflow.com/a/719941/745969 – Tim Apr 25 '13 at 06:05
  • Yes Tim i have seen this before. Its working successfully in localhost. But when i publish it in IIS the issue arises. Am i missing something to provide to IIS to fully access the web.config? – Saikat Apr 25 '13 at 06:09
  • Make sure the account the app pool is using has rights to read/write to the directory the Web.config is in. – Tim Apr 25 '13 at 06:21
  • Please elaborate Tim. May be this is the answer of my issue. – Saikat Apr 25 '13 at 06:31
  • You're web application runs under a user account (the default varies depending on the version of IIS, or you can set it to a specific account. In IIS, see which App Pool "owns" your app, then see what account is running the App Pool (like `Network Service`, for instance). Then check and see if that account has write permissions to the root of the application (it already has read). – Tim Apr 25 '13 at 06:33
  • Thank you very much Tim.Let me check. – Saikat Apr 25 '13 at 06:36

1 Answers1

2

you can't do that.

A web app cannot modify it's own config file. It is a security measure that you absolutely should NOT circumvent.

Other options: Store the value in the session state. Or in the cache? Or in a global static hashtable?

Normally client specific stuff should be stored in the session state (if you have that enabled).

Remember that you likely have multiple clients at the same time, so you would need to keep track of that.

Note: Why would you want to store the IP? It is a property readily available to all your codebehind classes - so why store it?