Web Application Server Issues - c#

I have a web application saved on a server. I want to be able to create an XML file for each user that logs onto the web app (using the users Windows log in when on the domain. The users log in needs to be the file name of the XML file.
I want to then save the file to a shared drive.
How can I do this?

You have to set up a service which is called on log event. On your service, you have to write your xml file and save it as the user name. The user name can be catched with HttpContext.Current.User.Identity.Name.
Is it what you want ?

I think you need to break up the process you are describing into logical and simple to achieve tasks.
Authenticate a user using Windows Authentication and Impersonation.
Access the user's domain username.
Create an XML file on a shared drive.
Open and edit an XML file on a shared drive.
Each of these tasks are relatively easy and have many resources on the web for how to achieve them using your language of choice.
If you are having trouble doing one of the particular parts of the process you describe above, be specific with what you are having a problem achieving, and we can help.

Related

How to configure a shared log folder with non-read access for other users files?

I have a c# application deployed to thousands of machines that writes log files to a shared log folder on a Windows server, e.g. "M:\VSDRW00121\Logs\MyApplication". The log files have the file name [MACHINE_NAME]_[USER_NAME].log so that multiple users can write their log files there.
Is there a way to configure so that a user can not read/delete/modify log files from other users on this Windows server (I assume there is)? Maybe my application will simply have to set the permissions programmatically when the log file is created so that no other users can read or edit the file or maybe this can be configured on a folder level configuration somehow?
In an ideal world, I would also like to prevent the user himself/herself from modifying his/her own log file as it is there for compliance reasons. But I am not sure if this is possible right? As the application will need to have write access to actually create and write the log file with new data?
Many thanks in advance if you have the chance to help me with this.

Read an xml file from different computer on the network?

To begin with, I developed a web application which reads an XML file from specific location and displays the contents on editable web page of the application,which is executed perfectly when the XML file is on the same machine/computer. When I try to read the same file on different computer on the network I cannot read the contents onto my web page.
My Observation:
When I access that file from run window in the computer by entering \xxx.xxx.xx.xx\c$ it gives me the window to connect to the machine asking for credentials and I guess the session is open. So I close the window and when I access the xml file from the web application it's able to read the content.
Is there a way to bypass this authentication mechanism which is part of windows when I use my web app to read the XML file or is there a way to accommodate the extra step to configure the authentication in my application?
I would be glad if someone can guide me to the solution.
Check the user your web application is running under and if this user is also permitted to access this location.
If you are using IIS to host the page you have to check the "AppPool" user and also the users which are used at the "Web Site" and "Application"
Just change IIS application pool user to "enough rights" user (right click current app pool - advanced settings - identity) or specify impersonation in the same name section in web.config.
Could it be possible to change your logic,
By storing file from different network to local machine where your code is running, through uploading file and process it.

Passing file data between Administration app and Web site app

We have two separate web applications for a site: One for the site itself, and one for the cms/administration side. I'm not sure why the original developer designed it this way, but whatever.
I am tasked with adding some functionality to the administration side that uploads files. These files then need to exist within the folder structure of the actual site. I was thinking I might have to write a web service that sits on the actual site that accepts the file bytes and file name from a call within the administration site, and creates the file in the correct folder, but I was wondering if anyone had any ideas about a cleaner way to accomplish the same thing.
In general, how would you tackle a scenario where you upload a file on one site, and send it to the directory structure in another?
Thanks in advance!
The solution I ended up going with is to store the full file path to the other site in the web.config. It's not the most elegant solution, but it works and I'm mildly happy with it since it is easily maintainable across dev/staging/production.
You could create a Windows Service to transfer the uploaded files from one folder to another.
After a file is uploaded on the admin site, the windows service moves the file over to the correct location on the other site. You just need to decide how to communicate with the service - you could add details about the uploaded file to a message queue that the service monitors or perhaps you windows service might just watch the upload folder for any new files.

Monitor File for Read and Change Data?

Is there any way, using C#, to monitor a specific file then change its contents before it is read by specific applications?
Here is the situation:
I have a Windows 2003 Server running ASP.NET with a configuration file (xml) which contains LDAP information. I want to have the LDAP password encrypted. I'm trying to devise a way to monitor that file, and whenever it is read, decrypt the LDAP password and pass that to whatever is reading it. Is there any way to tell which program is doing the read? I aldready have the encrypt/decrypt working but it is built into the ASP.NET installation; I would like to make it external. The encrypt/decrypt is RSA using key's from the key store.
If you want the encrypt/decrypt external to your main application, what about creating a separate .dll or webservice that does that. Then your call in your ASP.NET application is to your webserice or .dll.
Something like (Warining: Not Compiled- you'll need to clean this up)
WebServiceInstance instance = new WebServiceInstance();
string password = instance.PerformGetPassword();
Then, your ASP.NET service is unaware of the encrypted password at all. Additionally, if you have other applications which need to access the same file, they can call the same webservice.
I think this would be much better accomplished by using NTFS permissions on the file. Grant access only to certain users/groups, and ensure that any process requiring access to the secured data is running under the security context of a user that has the correct ACL permissions.

Uploading/Pushing Data To A Website

I need to let a company push information up to my site.
The best way to explain what I am talking about is to explain how it is currently done with their previous website:
This company uploads a CSV file to an FTP set up by the website. The website then processes the CSV file and puts it into an SQL database so that it can be used by the website.
In this case, I am the website and I am working with the company. Both sides are willing to change what they do. So my question is...
What is the best way to accept batch information like this? Is there a more automated way that doesn't involve FTP? In the future I may have a lot of companies wanting to do this, and I'd hate to have to setup accounts for each one.
The project is C# ASP.NET MSSQL
Let me know if you need more information...
Set up a web service to accept incoming data. That way you can validate immediately and reject bad data before it ever gets into your system.
If you want to eliminate FTP, you could allow them to upload files to your site leveraging using FileUpload. Once the file is uploaded you can do your server side processing.
EDIT: From the OP's comment's it seems to be an automated process. That said, if their process generates the file, you could:
Allow them to continue their current process which would involve them generating their file and placing it somewhere where it could be accessed via a URI with authentication, you could access this file on a schedule and process it. From what it seems right now they generate a file and upload it to your FTP server, so there seems to a manual element to begin with.

Categories