maidstone
asked on
Upload file via ASP.NET to Network Share Drive - USERNAME AND PASSWORD REQ
What I am trying to do is upload a file from the local computer onto a network share drive.
I am not quite sure how to add a Username/Password to my code below... I've taken the code from here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuihtmlcontrolshtmlinputfileclasstopic.asp
Can anyone help?
Thanks in advance....
HTML
-------------------------- ---------- ---------- ----
Select File to Upload: <input id="File1" type="file" name="File1" runat="server">
<p>Save as filename (no path): <input id="Text1" type="text" name="Text1" runat="server">
<p><span id="Span1" style="FONT: 8pt verdana" runat="server"></span>
<p><input id="btnUpload" type="button" value="Upload" name="btnUpload" runat="server">
VB.NET SCRIPT
-------------------------- ---------- ---------- ---------- --
Private Sub btnUpload_ServerClick(ByVa l sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.ServerClick
If Text1.Value = "" Then
Span1.InnerHtml = "Error: you must enter a file name"
Return
End If
If Not (File1.PostedFile Is Nothing) Then
Try
File1.PostedFile.SaveAs((" \\{server} \{Director y}\" & Text1.Value))
Span1.InnerHtml = "File uploaded successfully to the <b>server as " & _
Text1.Value & "</b> on the Web server"
Catch exc As Exception
Span1.InnerHtml = "Error saving file to the <b>Server as " & _
Text1.Value & "</b><br>" & exc.ToString()
End Try
End If
End Sub
I am not quite sure how to add a Username/Password to my code below... I've taken the code from here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuihtmlcontrolshtmlinputfileclasstopic.asp
Can anyone help?
Thanks in advance....
HTML
--------------------------
Select File to Upload: <input id="File1" type="file" name="File1" runat="server">
<p>Save as filename (no path): <input id="Text1" type="text" name="Text1" runat="server">
<p><span id="Span1" style="FONT: 8pt verdana" runat="server"></span>
<p><input id="btnUpload" type="button" value="Upload" name="btnUpload" runat="server">
VB.NET SCRIPT
--------------------------
Private Sub btnUpload_ServerClick(ByVa
If Text1.Value = "" Then
Span1.InnerHtml = "Error: you must enter a file name"
Return
End If
If Not (File1.PostedFile Is Nothing) Then
Try
File1.PostedFile.SaveAs(("
Span1.InnerHtml = "File uploaded successfully to the <b>server as " & _
Text1.Value & "</b> on the Web server"
Catch exc As Exception
Span1.InnerHtml = "Error saving file to the <b>Server as " & _
Text1.Value & "</b><br>" & exc.ToString()
End Try
End If
End Sub
ASKER
I dont think I quite understand either...
They both have to do with a Windows Web Server.
So if you are wanting to put a file somewhere where the servers are connected, the only way to save a file somewhere is to have a Username/Password that has access to the place.
So in Web Server land there are 2 places. 1 is the Application Pool Identity that is set in Internet Services Manager on the web server, and the other one is to authenticate via code and use the Username and Password (to create a Windows Principal) and then save the file.
The first one is more common because the Windows Principal concept for something like this is way overkill and more complex.
Does that help?
So if you are wanting to put a file somewhere where the servers are connected, the only way to save a file somewhere is to have a Username/Password that has access to the place.
So in Web Server land there are 2 places. 1 is the Application Pool Identity that is set in Internet Services Manager on the web server, and the other one is to authenticate via code and use the Username and Password (to create a Windows Principal) and then save the file.
The first one is more common because the Windows Principal concept for something like this is way overkill and more complex.
Does that help?
ASKER
What you are saying makes no sence to me....
What I did was just put a entry into my Web.Config file....
<identity impersonate="true" userName="{Username}"
password="{Password}" />
I don't think thats the solution you were trying to get accross to me, so I went a different direction.
What I did was just put a entry into my Web.Config file....
<identity impersonate="true" userName="{Username}"
password="{Password}" />
I don't think thats the solution you were trying to get accross to me, so I went a different direction.
Whatever the recommendation or protocol is works for me.
Ben.
Ben.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
1) is to have the user that is in the Application Pool identity be a user that can auto pass through in authentication because the same user exists on the network machine you are connecting to.
2) You can Create a Windows Identity principal and use the username and password and then impersonate and save. This is the more intensive one because there are ramifications that you need to make sure that you protect yourself from and this is also the slowest because it involves authentication of each request.
Does this make sense?