473,797 Members | 3,204 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Network access from c# code (called from ASP.Net)

Hello
We have a web application written in ASP.Net that calls an external C# program (.exe). This C# program needs to access data from a different server and is not able to do so. We use impersonate in the web config for the ASP code to be able to access the network and it is working fine. But since the C# exe is being called from the ASP code, it is apparently not running with the privileges of the userID specified in the web.config for the ASP code
We tried trusting this assembly using the .Net Framework wizard to the highest level possible, but that didn't help. If we change the machine.config and hardcode the userid and password in the "process model" (change the system/autogenerate), the C# program is able to access the network, but I am not sure that is the right way to do this..
We call the exe by using System.Diagnost ics.Process .Start (we specify the startinfo.filen ame as the filename of the C# exe to execute

We don't have the C# code (just the exe), so putting the functionality of the C# program into the ASP page code is not an option

Could someone please help figure out the ideal way to do this?
Thanks
Nov 22 '05 #1
9 2901
"Joseph" <jo**********@n ospam.com> wrote in message
news:B0******** *************** ***********@mic rosoft.com...
Hello,
We have a web application written in ASP.Net that calls an external C# program (.exe). This C# program needs to access data from a different
server and is not able to do so. We use impersonate in the web config for
the ASP code to be able to access the network and it is working fine. But
since the C# exe is being called from the ASP code, it is apparently not
running with the privileges of the userID specified in the web.config for
the ASP code. We tried trusting this assembly using the .Net Framework wizard to the highest level possible, but that didn't help. If we change the
machine.config and hardcode the userid and password in the "process model"
(change the system/autogenerate), the C# program is able to access the
network, but I am not sure that is the right way to do this... We call the exe by using System.Diagnost ics.Process .Start (we specify the startinfo.filen ame as the filename of the C# exe to execute)
We don't have the C# code (just the exe), so putting the functionality of the C# program into the ASP page code is not an option.
Could someone please help figure out the ideal way to do this?
Thanks


I'd recommend this article that a friend had sent to me.
http://www.15seconds.com/Issue/020312.htm

Nov 22 '05 #2
Thank you for your quick response... I am able to get the application to work by modifying the proceess model user ID/password in the machine.config. The only concern I have with this approach is that any other .Net web application that I install on this server will automatically get the rights that this user ID has and that is not something desirable. Is there a way that I can give these rights only the C# program that I am calling in my code (and not to any other application that might be installed at a later point in time)

Thanks
Nov 22 '05 #3
"Joseph" <jo**********@n ospam.com> wrote in message
news:6E******** *************** ***********@mic rosoft.com...
Thank you for your quick response... I am able to get the application to work by modifying the proceess model user ID/password in the machine.config.
The only concern I have with this approach is that any other .Net web
application that I install on this server will automatically get the rights
that this user ID has and that is not something desirable. Is there a way
that I can give these rights only the C# program that I am calling in my
code (and not to any other application that might be installed at a later
point in time)?
Thanks


This might be what you're looking for, search VS.NET docs for "Impersonat ing
and Reverting". It appears to work similarly (in function) to the su command
on UNIX.

Nov 22 '05 #4
Hello Jose,

For this question, please refer to this KB artile:
"INFO: Implementing Impersonation in an ASP.NET Application"
http://support.microsoft.com/?id=306158

You can refer to the "Impersonat e a Specific User for All the Requests of
an ASP.NET Application" part in this article.
1) Grant the "Act as part of the operating system" privilege to the ASPNET
account (the least privileged account). In this way, you can grant right in
a special location and then undoimpersonate it when finished.
2) Change the account that the Aspnet_wp.exe process runs under. However,
this may not what you want.

Specially, you can Impersonate a user in code according to the other two
methods in that KB article. Please try them and let us know whether it
works for you.

Does that answer your question?

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 22 '05 #5
Hello Joseph,

When you change machine.config to a network logon ID, the asp.net worker
process are spawn under that network logon ID identity. Also, the spawn C#
program process is under that network logon ID identity. You can prove it
by watching task manager in the system.

When you change to that network logon ID in web.config, the asp.net worker
process are still spawn under aspnet account. However, the execution
context of asp.net worker process is that network logon ID. So you can
access network resource in asp.net code successfully. However, when you
spawn a C# program, that C# program are still under aspnet account (not
that network logon ID). The aspnet account are a local account and may not
have access to that network resource. Even after you add it to admin group,
it is still a local admin account. That should be the reason of the
program. I think you can also watch task manager in the system this time to
see the user name of this C# program.

To resolve it, we need to:

1) Change processmodel to the network logon ID in machine.config, as what
you did now.
2) You may also change the source code of that C# application, make network
logon ID and password as its parameters, and call LogonUser in that C#
program. So when you use CreateProcess to run C# program, the C# program
will impersonate by itself. This may resolve the problem for you. And it
won't affect other web applications on your machine.

If there is any unclear, please feel free to post here. Thanks very much.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 22 '05 #6
Hello Yanhong
Thank you for your suggestions... the only concern I have about changing the id/pwd in the processmodel is that every other asp application that is installed on this server will also have this same access and that is a risk that I am concerned about. Is there any way to ensure that only this C# program gets to use this network ID/pwd for access
Unfortunately, we don't have the access to the C# program (it is third party program) - else the best way would have been to implement that C# program code (or at least the network access part of it) in the web application itself where it could use the ID/pwd specified in the "impersonat e" of the web.confi

Could you suggest some way of ensuring that only this program gets to use this ID
Thanks again for your help
- Joseph
Nov 22 '05 #7
Hello Joseph,

If we change username/password in the machine.config file, all the web
applications using that version of asp.net will use that identity. This
can't be changed in asp.net application.

I totally understand your concern. That is also why I suggest you change
the code of that C# program. However, it seems that you can't do that
either due to not having source code.

There is no way to change the behavior if you use CreateProcess. I have
some other suggestions for you:

1) Call CreateProcessWi thLogonW to launch that C# program. This API has
usename and passwrod parameters. It may have the C# application run under a
network logon ID.

2) Or change the authentication level of that network resouce so that it
can trust the aspnet account of your local machine.

Thanks.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 22 '05 #8
Thank you for your response Yanhong. I haven't used the CreateProcessWi thLogonW yet - but it sounds promising! I will read up about that and hopefully that will help. I will update you on what I find

Thanks once again
Regard
- Joseph
Nov 22 '05 #9
Hi Joseph,

It is my pleasure to be of assistance. The keypoint here is to watch task
manager to see the owner of the C# process. If it changes to that domain
user account, then it should be OK. If it is still aspnet, then we have to
change machine.config to do that.

Thanks for working with us so closely. :)

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 22 '05 #10

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

Similar topics

2
584
by: klkuenzel | last post by:
Can you run a VB.NET executable from a network share on a server. My company does this with VB 6.0. Example ..Net executable on network file server called Toky client computer has a shortcut on desktop pointing to the executable: \\Tokyo\VBNET\myapp.ex Note executable uses SqlDataClient object Form comes up fine on client but when you try and run an update sql stored procedure application bombs with the error
12
444
by: Joseph | last post by:
Hello We have a web application written in ASP.Net that calls an external C# program (.exe). This C# program needs to access data from a different server and is not able to do so. We use impersonate in the web config for the ASP code to be able to access the network and it is working fine. But since the C# exe is being called from the ASP code, it is apparently not running with the privileges of the userID specified in the web.config for the...
5
8824
by: JohnFol | last post by:
I am using the Win23 API WNetCancelConnection2 and can sucessfully make a connection to a share within my class. The class is called from a Windows Form based test harness. When I instantiate exactly the samce class from a Windows Wervice, I get "A specified logon session does not exist. It may already have been terminated" .. The error number is 1312. I know the code to be good, so I suspect something around security / windows...
3
2031
by: Sue | last post by:
What is the difference between an intranet and a network? Can a split database be put on an intranet? Thanks! Sue
2
5143
by: Leonardo D'Ippolito | last post by:
Hi! I have two .NET win apps that need to communicate on a TCP/IP network. 'App A' must ask 'app B' if it's allowed to do some task, and 'app B' must authorize or prohibit it. How can I do this kind of communication in a secure way (protected from sniffing)? It would be a very simple protocol. Question, and two possible answers 'yes' or 'no'.
5
3662
by: Mike McIntyre [MVP] | last post by:
I am working on an issue where and ASP.NET web application on one computer (A) needs to access files on a network mapped drive (B). This application uses as DSN on (A) that maps a proprietory ODBC driver to data on a (B). The DSN directory path points to mapped network drive mounted on (A). When the ASP.NET application reaches the point where the ODBC drive is called to fill a DataSet it throws the following exeption:
8
11854
by: Lam | last post by:
HI anyone knows how can I open a mapped network file in C#? I try string file = @"T:\file.txt"; it shows me the error: "Could not find a part of the path" but if I copy the file to my C dirve, and use @"C:\file.txt"; it worked Thanks a lot
4
2031
by: Alex Maghen | last post by:
This is weird On my WinXP development box, database calls made from within my GLOBAL.ASAX go to SQLServer as user "ASPNET" even though I have impersonation turned on in my web.config. That's fine Now, when I move the whole application over to my Windows 2003 Server box, during the GLOBAL.ASAX calls to SQLServer, I get "Login failed for NT AUTHORITY\NETWORK SERVICE." I don't understand this. "NT AUTHORITY\NETWORK SERVICE" isn't even a user...
3
3604
by: Tomdhu | last post by:
As a Newbie I've picked up a heap of tips and tricks from this NG but I have been battling to get the current user's Netwok Login ID recorded on a form at the time a new record is created or modified. I haven't implemented Access security, and want their Network Login ID. The network is running W2K server and all users have unique login ID's. I run A2K and I've found Dev Ashish's code at http://www.mvps.org/access/api/api0008.htm . I...
1
510
by: 33223 | last post by:
Local Area Network (LAN) Both an EtherNet (wire) network and a wireless network are referred to as a Local Area Network (LAN). A wireless network does not require hubs, switchers, or routers to include additional users on the network. Additional wireless users are supported just by being in the immediate physical span of the network. A wireless LAN (or Wi-Fi network) may be configured in two different ways:
0
9537
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10209
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9066
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6803
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5459
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4135
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3750
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2934
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.