Suppress login dialog when impersonation on?

G

Gary H.

Does anyone know how I can suppress the "Enter Network
Password" dialog when attempting to enumerate directories
and/or files in ASP.NET? I want my code to automatically
generate an exception if the current user is not allowed
to access a share folder or file instead of prompting the
user to enter a username/pwd. I'm using:

dirs = Directory.GetDirectories(sPath)

Or, is there an easier way to determine if the current
user has access to a share folder/file?

Thanks, Gary.
 
F

Felix Wu [MSFT]

Hi Gary ,

You can use the try-catch block to catch the permission denied exceptions.
When you attempt to access files/folders that you are granted access to,
you will get SecurityException exceptions. You can catch the exceptions and
return a message to the user that he/her has no permission to the resource.

For example:

private void Button1_Click(object sender, System.EventArgs e)
{
try
{
string[] dirs=Directory.GetDirectories("H:\\WUTemp");
foreach(string dir in dirs)
DropDownList1.Items.Add(dir);
}
catch(Exception e1)
{
//Return a message to users
Label1.Text =e1.Message;
}
}

Regards,

Felix Wu
=======
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top