473,498 Members | 98 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Solution: Asp.Net and Smb shares - without impersonation

I've found a solution to this that I think I like, but I thought it wise to put
it out for all to see so people could punch holes in it as they wished. (Is
there a better way?)

I want a page in an Asp.Net site to be able to open/access a file that's on an
Smb share (ie. "Windows Share", "NetBios Share", etc.). I cannot use the
"ASPNET" username; that's a bad route to take anyhow (got to mess with the
"automatic" password settings and other worms in the can you'll be opening).

At first glance, everyone seems to suggest using the "identity" tag in
web.config to do impersonation. However, it's a huge PITA; there's more to it
than what's described in KB #317012 or at the following
http://msdn.microsoft.com/library/en...l/secmod15.asp
For example, your new user won't have permission to access
System.Diagnostics.Process.GetCurrentProcess().Han dle
among other various "gotchas". Impersonation is overkill.

The solution?
Use System.Diagnostics.Process and run "net use" from the Asp.Net application
to authenticate to your network share. The authentication will last just like it
does when you call it from the command line (for the user you execute it as).

I believe this method to be the least invasive on existing code. For me, I have
a File.Exists check first. If that fails, then I try to open the file
(File.OpenText is what I tested with, but File.Open should be the same). If the
exception is

[System.IO.IOException] Logon failure: unknown user name or bad password.

then I do the "net use" call to authenticate and try again. If it's not that
exception, then the file will actually not exist, and you get this error:

[System.IO.FileNotFoundException] Could not find file "<filename>"

and I then let the exception propagate to my error-handling stuff.
Nov 18 '05 #1
3 2762
Don't you have to give the ASPNET account broad permissions to execute "net
use"? It seems like that's a pretty big security hole.

I'd still prefer to use impersonation to authenticate to the network share.

"Granger Godbold" <gr*************@invalid.prometric.com> wrote in message
news:u0**************@tk2msftngp13.phx.gbl...
I've found a solution to this that I think I like, but I thought it wise
to put it out for all to see so people could punch holes in it as they
wished. (Is there a better way?)

I want a page in an Asp.Net site to be able to open/access a file that's
on an Smb share (ie. "Windows Share", "NetBios Share", etc.). I cannot use
the "ASPNET" username; that's a bad route to take anyhow (got to mess with
the "automatic" password settings and other worms in the can you'll be
opening).

At first glance, everyone seems to suggest using the "identity" tag in
web.config to do impersonation. However, it's a huge PITA; there's more to
it than what's described in KB #317012 or at the following
http://msdn.microsoft.com/library/en...l/secmod15.asp
For example, your new user won't have permission to access
System.Diagnostics.Process.GetCurrentProcess().Han dle
among other various "gotchas". Impersonation is overkill.

The solution?
Use System.Diagnostics.Process and run "net use" from the Asp.Net
application to authenticate to your network share. The authentication will
last just like it does when you call it from the command line (for the
user you execute it as).

I believe this method to be the least invasive on existing code. For me, I
have a File.Exists check first. If that fails, then I try to open the file
(File.OpenText is what I tested with, but File.Open should be the same).
If the exception is

[System.IO.IOException] Logon failure: unknown user name or bad password.

then I do the "net use" call to authenticate and try again. If it's not
that exception, then the file will actually not exist, and you get this
error:

[System.IO.FileNotFoundException] Could not find file "<filename>"

and I then let the exception propagate to my error-handling stuff.


Nov 18 '05 #2
You could also try defining an application pool (I am assuming IIS6) and
define a specific identity to use/application account that has access to the
requested resource (as well as the same privileges as ASPNET user so that it
can run .Net apps). Alternatively (although I would also view this as
overkill) is you can define a COM+ component (ie. inherit from
ServicedComponent) and install the component that needs to access the remote
resource into COM+. You could then define a specific identity/user account
under which it would run, and again you would give/assign that user the
required access.

Just some other options.

--
- Paul Glavich
Microsoft MVP - ASP.NET
"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Don't you have to give the ASPNET account broad permissions to execute "net use"? It seems like that's a pretty big security hole.

I'd still prefer to use impersonation to authenticate to the network share.
"Granger Godbold" <gr*************@invalid.prometric.com> wrote in message
news:u0**************@tk2msftngp13.phx.gbl...
I've found a solution to this that I think I like, but I thought it wise
to put it out for all to see so people could punch holes in it as they
wished. (Is there a better way?)

I want a page in an Asp.Net site to be able to open/access a file that's
on an Smb share (ie. "Windows Share", "NetBios Share", etc.). I cannot use the "ASPNET" username; that's a bad route to take anyhow (got to mess with the "automatic" password settings and other worms in the can you'll be
opening).

At first glance, everyone seems to suggest using the "identity" tag in
web.config to do impersonation. However, it's a huge PITA; there's more to it than what's described in KB #317012 or at the following
http://msdn.microsoft.com/library/en...l/secmod15.asp
For example, your new user won't have permission to access
System.Diagnostics.Process.GetCurrentProcess().Han dle
among other various "gotchas". Impersonation is overkill.

The solution?
Use System.Diagnostics.Process and run "net use" from the Asp.Net
application to authenticate to your network share. The authentication will last just like it does when you call it from the command line (for the
user you execute it as).

I believe this method to be the least invasive on existing code. For me, I have a File.Exists check first. If that fails, then I try to open the file (File.OpenText is what I tested with, but File.Open should be the same).
If the exception is

[System.IO.IOException] Logon failure: unknown user name or bad password.
then I do the "net use" call to authenticate and try again. If it's not
that exception, then the file will actually not exist, and you get this
error:

[System.IO.FileNotFoundException] Could not find file "<filename>"

and I then let the exception propagate to my error-handling stuff.

Nov 18 '05 #3
No. You don't. I didn't have to change anything on the ASPNET account for it to
work correctly.
Ken Cox [Microsoft MVP] wrote:
Don't you have to give the ASPNET account broad permissions to execute
"net use"? It seems like that's a pretty big security hole.

I'd still prefer to use impersonation to authenticate to the network share.

"Granger Godbold" <gr*************@invalid.prometric.com> wrote in
message news:u0**************@tk2msftngp13.phx.gbl...
I've found a solution to this that I think I like, but I thought it
wise to put it out for all to see so people could punch holes in it as
they wished. (Is there a better way?)

I want a page in an Asp.Net site to be able to open/access a file
that's on an Smb share (ie. "Windows Share", "NetBios Share", etc.). I
cannot use the "ASPNET" username; that's a bad route to take anyhow
(got to mess with the "automatic" password settings and other worms in
the can you'll be opening).

At first glance, everyone seems to suggest using the "identity" tag in
web.config to do impersonation. However, it's a huge PITA; there's
more to it than what's described in KB #317012 or at the following
http://msdn.microsoft.com/library/en...l/secmod15.asp
For example, your new user won't have permission to access
System.Diagnostics.Process.GetCurrentProcess().Han dle
among other various "gotchas". Impersonation is overkill.

The solution?
Use System.Diagnostics.Process and run "net use" from the Asp.Net
application to authenticate to your network share. The authentication
will last just like it does when you call it from the command line
(for the user you execute it as).

I believe this method to be the least invasive on existing code. For
me, I have a File.Exists check first. If that fails, then I try to
open the file (File.OpenText is what I tested with, but File.Open
should be the same). If the exception is

[System.IO.IOException] Logon failure: unknown user name or bad password.

then I do the "net use" call to authenticate and try again. If it's
not that exception, then the file will actually not exist, and you get
this error:

[System.IO.FileNotFoundException] Could not find file "<filename>"

and I then let the exception propagate to my error-handling stuff.


Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
8998
by: David Moore | last post by:
Hello I posted a thread about this a while back, but I can't actually find it again so I can reply to it with the solution I found, so I'm making a new thread and hoping it goes to the top of...
3
5141
by: Chris | last post by:
Hello all, Here is my problem. I have a windows service (C#) that is supposed to move files from/to the local drive to/from a UNC share (\\domainserver\share). The service is running on a Win3k...
12
2539
by: Anil Krishnamurthy | last post by:
We have an ASP.NET application that uses COM objects through Interop. The web application requires access to network and database resources and hence, needs to impersonate a domain account. The...
2
1462
by: zerokarma | last post by:
I've recently setup a webfarm using win2k3 and a network disc array to store all the files served up by the webfarm. All web sites being hosted are configured to work over UNC. My problem is IIS...
3
2110
by: Caspy | last post by:
I just get stuck on how to check if a user is a member of network (domain). I am building an internal tracking system with ASP.Net with Form authentication. When an user is added into the system,...
5
10160
by: Josh Rolfe | last post by:
I have a page in classic asp that accces a network drive, The code is as follows: <% dim fso dim objFolder set fso=server.createObject("Scripting.FileSystemObject") set...
11
1277
by: Oliver | last post by:
Hi, I'm working on an ASP.NET application that allows users to upload images to a central storage area and view using a HTTP handler. This works great if the files are stored on a local drive...
2
1104
by: Mantorok | last post by:
Hi I have an app and during some code-behind it attempts to fetch some files from another server-share, IIS is configured to use the users windows-login as authentication and although we have...
2
4693
by: Wimpie van Lingen | last post by:
Hey I have some more questions with regards to Remoting in .NET 2. I'm using TCP with the Binary formatter. My solution consists of 4 projects: - Class Library containing the server classes...
0
7124
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4904
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
651
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.