Actually i m trying to make a setupfile for my project.That makes some processes and at the end of processes will change web.config Database connectionstring values and will run project.Evertthing
is good but cant reach to web.config file beacuse of permissions.
Project will run on out of company hosting account.So i cant reach IIS to change permissions.
So please offer me a way or if you know solution.Please help.
I also thinking on downloading web.config file with ftp account and change it and reupload back with programaticly in code.
Waht you think???
ERROR:
System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Access to the path 'C:\Inetpub\vhosts\xxx.com\httpdocs\rouqudck.tmp' is denied. (C:\Inetpub\vhosts\xxx.com\httpdocs\web.config) ---> System.UnauthorizedAccessException:
Access to the path 'C:\Inetpub\vhosts\xxx.com\httpdocs\rouqudck.tmp' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights,
FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) at
Hi,
I tried your code block on server...
And got same permission error;
Access to the path 'C:\Inetpub\vhosts\finssmart.com\httpdocs\Web.config' is denied.
Actually i solved this problem with a simple method.
I am creating a new web.config file including my new connectionstring data and sending it with my ftp code block.So it uploads web.config to the server.:)
Have you added Network service account to web.config? Right click on web config, go to security and add "Network Service" account and try again. Let me know your results.
I added "NETWORK SERVICE" account to web.config and gave all permissions (Full control) to it. It works on my machine. Web.cofig has been changed successfully. Can you try again?
fatihcewik
Member
2 Points
10 Posts
Tring to write to web.config file error Access to the path
Oct 16, 2010 10:47 PM|LINK
Hi Friends.
Actually i m trying to make a setupfile for my project.That makes some processes and at the end of processes will change web.config Database connectionstring values and will run project.Evertthing is good but cant reach to web.config file beacuse of permissions.
Project will run on out of company hosting account.So i cant reach IIS to change permissions.
So please offer me a way or if you know solution.Please help.
I also thinking on downloading web.config file with ftp account and change it and reupload back with programaticly in code.
Waht you think???
ERROR:
System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Access to the path 'C:\Inetpub\vhosts\xxx.com\httpdocs\rouqudck.tmp' is denied. (C:\Inetpub\vhosts\xxx.com\httpdocs\web.config) ---> System.UnauthorizedAccessException: Access to the path 'C:\Inetpub\vhosts\xxx.com\httpdocs\rouqudck.tmp' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) at
Best Regards
Fatih CEVIK
www.fatihcevik.com
cninjas
Contributor
4868 Points
851 Posts
Re: Tring to write to web.config file error Access to the path
Oct 18, 2010 11:55 AM|LINK
hi
I think the access problem is bcaz you are trying to write in the INETPUB.Instead can you try some other folder outside Inepub.
And moreover what is the methodology you are using for writing it to the web.config?
I came across a sample..chk whether it will be useful for you...
private void SetConfigSettings() { string path = Server.MapPath("Web.config"); string newConnectionString = @"Server=local;Database="+txtDatabaseName.Text+";Trusted_Connection=true"; XmlDocument xDoc = new XmlDocument(); xDoc.Load(path); XmlNodeList nodeList = xDoc.GetElementsByTagName("appSettings"); XmlNodeList nodeAppSettings = nodeList[0].ChildNodes; XmlAttributeCollection xmlAttCollection = nodeAppSettings[0].Attributes; xmlAttCollection[0].InnerXml = txtKey.Text; // for key attribute xmlAttCollection[1].InnerXml = newConnectionString; // for value attribute xDoc.Save(path); // saves the web.config file }Hope it helps...thanks,
Niranjan
fatihcewik
Member
2 Points
10 Posts
Re: Tring to write to web.config file error Access to the path
Oct 18, 2010 12:34 PM|LINK
Hi.Thanks for your replay my firend
Here is my code that try to save connection string to web.config
System.Configuration.Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");
// AppSettingsSection appSettingsSection = (AppSettingsSection)configuration.GetSection("appSettings");
// if (appSettingsSection != null)
// {
// appSettingsSection.Settings["strConnection"].Value = "Data Source=" + DbServerName+ ";Initial Catalog=" + DbName+ ";User ID=" + DbUserName + ";Pwd=" +DbUserPass+ "";
// configuration.Save();
and now i will try ur suggession...
www.fatihcevik.com
fatihcewik
Member
2 Points
10 Posts
Re: Tring to write to web.config file error Access to the path
Oct 18, 2010 12:49 PM|LINK
Hi,
I tried your code block on server...
And got same permission error;
Access to the path 'C:\Inetpub\vhosts\finssmart.com\httpdocs\Web.config' is denied.
Actually i solved this problem with a simple method.
I am creating a new web.config file including my new connectionstring data and sending it with my ftp code block.So it uploads web.config to the server.:)
What do you think for this method?
Regards
Fatih
www.fatihcevik.com
mzubair10
Member
118 Points
118 Posts
Re: Tring to write to web.config file error Access to the path
Oct 18, 2010 02:36 PM|LINK
Have you added Network service account to web.config? Right click on web config, go to security and add "Network Service" account and try again. Let me know your results.
fatihcewik
Member
2 Points
10 Posts
Re: Tring to write to web.config file error Access to the path
Oct 18, 2010 02:47 PM|LINK
Hi,
Need to say that project not runn,ng on my server.So i can only can reach permissions on plesk.
And i gave all permissions i can...it doesnt solve
???
www.fatihcevik.com
Wenchao Zeng...
Star
14673 Points
1496 Posts
Re: Tring to write to web.config file error Access to the path
Oct 20, 2010 03:25 AM|LINK
Hi,
I added "NETWORK SERVICE" account to web.config and gave all permissions (Full control) to it. It works on my machine. Web.cofig has been changed successfully. Can you try again?
Hope this helps.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework