Last post Mar 26, 2014 05:59 AM by smirnov
Mar 26, 2014 05:23 AM|smilu.net|LINK
I have an application where I'm storing files into a network Folder. I have set the permission of the folder to write for "Everyone". Still its showing me "Unauthorized access". So, I thought of going withIdentity. I cannot write my username and password
in the web.config since it will be readable. So, I'm trying to override the data with Username and password from code behind. But when i run the application it doesnt work and says "Unauthorized access". Here are the steps which I have followed.
In web.config i have set
<identity impersonate="false" />
Now from coding I'm changing identity properties like this.
System.Configuration.Configuration configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/");
System.Web.Configuration.IdentitySection id = (System.Web.Configuration.IdentitySection)configuration.GetSection("system.web/identity"); // new System.Web.Configuration.IdentitySection();
id.Impersonate = true;
I don't know whether this will override it[When we debug it shows the new data as the IdentitySection]. But when I read MSDN its written we can override the username and password. I referred to the links below and reached upto here. But it doesn't work.
I'm again getting the same error.
If we add the Identity Impersonate section with username and password in the web.config it works perfectly.
Do anyone know how to write this from code behind.
NOTE: I have referred other links showing identity impersonation which is quite big with some dllimport etc etc. Without this can we implement.
Mar 26, 2014 05:42 AM|smirnov|LINK
I have set the permission of the folder to write for "Everyone".
Did you set permissions for the file share?
Mar 26, 2014 05:46 AM|smilu.net|LINK
I said know. Its already shared and I can run it locally and with <identity imperonate="true" username="doman\user" password="password"/> from webserver.
Mar 26, 2014 05:59 AM|smirnov|LINK
This question has been asked many times here on this forum. Please check this thread http://forums.asp.net/t/1934712.aspx?Correct+way+to+access+a+file+share, which should
help. In general if you do not want to use impersonation you need to check account which you use to run the website and based on that configure the remote folder. If you want to use impersonation then your code is not the one you need. It just tries to do
something with the web.config configuration and does not affect on identity. See complete example here http://support.microsoft.com/kb/306158