Last post Oct 30, 2019 02:29 AM by Ressa_Panda
Oct 23, 2019 03:40 AM|Ressa_Panda|LINK
I have developed a web application which has a feature to upload image and to display the image in a web page as well as to download the image.
I have my IIS admin to deploy it to the server and usually i used Server IP Address/Applicationname (exp: 192.168.0.59/MvcImage) to access my system. The images are stored in a remote shared network folder which has an IP Address. In order to connect to
the network i used WNetAddConnection following the example in (https://www.c-sharpcorner.com/blogs/how-to-access-network-drive-using-c-sharp)
because i keep on getting UnauthorizedAccessException. The solution above worked if i used IpAdress/aplicationName to access my web application. However, the same exception which is UnauthorizedAccessException occured when i try to access the same web page
using an alias url that the IIS admin created for my web application (exp:
Here is some of the codes for establishing connection to the network drive:
private int ConnectToShare(string remoteUnc, string username, string password, bool promptUser)
NETRESOURCE nr = new NETRESOURCE
dwType = RESOURCETYPE_DISK,
lpRemoteName = remoteUnc
result = WNetUseConnection(IntPtr.Zero, nr, "", "", CONNECT_INTERACTIVE | CONNECT_PROMPT, null, null, null);
result = WNetUseConnection(IntPtr.Zero, nr, password, username, 0, null, null, null);
//if (result != NO_ERROR)
// throw new Win32Exception(result);
public int AccessCredentials(string remoteComputerName, string userName, string password)
RemoteComputerName = remoteComputerName;
UserName = userName;
Password = password;
return this.ConnectToShare(this._remoteUncName, this.UserName, this.Password, false);
Here is the code to check if the credentials to access the network folder is valid and the code to retrieve the file from the network folder
public bool CredentialIsValid()
NetworkCredentials credentials = new NetworkCredentials();
bool valid = false;
int status = credentials.AccessCredentials(Paths.networkPath, Paths.networkUsername, Paths.networkPassword);
if (status == 0 || status == 1219)
valid = true;
public FileViewModel GetFile(string fullPath)
FileViewModel file = new FileViewModel();
WebClient client = new WebClient();
file.fileData = client.DownloadData(Path.GetFullPath(fullPath));
file.fileName = Path.GetFileName(fullPath);
file.fileType = Path.GetExtension(fullPath);
And here is the code in controller to execute the codes above
public ActionResult DisplayImage(string fullPath)
FileViewModel file = mgr.GetFile(fullPath);
if(file.fileData == null)
return File(file.fileData, file.fileType, file.fileName);
I only got this problem when i used Https:// as my url. If i deleted the Https:// from the url, the image can be accessed (viewed/downloaded) like intended.
I am so confused that i do not even know if this is problem with my coding or server configuration/IIS/DNS configuration as i am not really good in networking
Any advice/help would be appreciated
Oct 24, 2019 09:58 AM|Yongqing Yu|LINK
As far as I know, the windows auth has two mode : NTLM and kerberos.
If you use the ip address to access the web application, it will use NTLM by default. If you use domain to access the web application, it will use kerberos by default.
If you use the kerberos you may faced this access issue.
The solution is you should add SPN setting for the domain.
For more details ,you could refer to this article:
Setting up Kerberos Authentication for a Website in IIS
Oct 30, 2019 02:29 AM|Ressa_Panda|LINK
Thanks for the reply and sorry for the late reply,
I did not get notified on this reply,
So, using alias like https://something.something.com/AppName would uses Kerberos,
Just to confirm things:
All of the application functionality are working fine, but when i tried to access the Network Attached Storage which is the remote server that i talked about above i got this error saying Access to "Path" is denied. I am also using the ip address to access
So i could access the web application using https no error encountered,
the problem occurred when i am trying to access the NAS. Would this answer still be relevant?