Ajax Uploader and logged in user

Last post 07-29-2008, 3:10 PM by Adam. 5 replies.
Sort Posts: Previous Next
  •  07-23-2008, 11:08 AM 42474

    Ajax Uploader and logged in user

    I am using asp.net membership for security.  Do you have any documentation/tips on how to tie the uploader in with membership in order to populate the userid fields in the tables with the current logged in user?
     
    Currently the application uploads all files as 'Guest' (userid = 1).
     
    Thanks for your assistance.
     
    Ed
  •  07-23-2008, 1:27 PM 42481 in reply to 42474

    Re: Ajax Uploader and logged in user

    Ed,
     
    Can you explain it in details?
     
    Are you using Ajax Uploader in a custom solution?
     
    By default, Ajax Uploader doesn't change the file name.
     
      void Uploader_FileUploaded(object sender, UploaderEventArgs args)
            {
                Uploader uploader = (Uploader)sender;
                InsertMsg("File uploaded! " + args.FileName + ", " + args.FileSize + " bytes.");
                
                //Copies the uploaded file to a new location.
                //args.CopyTo("c:\\temp\\"+args.FileName);
                //You can also open the uploaded file's data stream.
                //System.IO.Stream data = args.OpenStream();
            }

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  07-26-2008, 10:58 AM 42559 in reply to 42481

    Re: Ajax Uploader and logged in user

    Thanks for the reply Adam. Maybe I can do a better job explaining my issue:
     
    I am using the Ajax Uploader in a custom solution.  I do not need to change the filename, I just need to pass
    the currently logged in user id (from membership) to AJAX Uploader. I want to populate the UserId column in the UploaderFiles SQL Table with the currently logged in user (logged in through asp.net membership).
     
    Specifically referring to the below bit of code in SampleDB.vb. It always comes back as Guest.  Is it because there isn't a "CurentUserRow" in "Context.Items" (I see a 'user' item but no 'CurentUserRow' when I debug)? Perhaps this is a typo in the SampleDB code?
     
    I wanted to make sure there wasn't an 'easy' way to do this before going in and changing things.
     
    Thanks for your help Adam!

    Public Shared Function GetCurentUserRow() As DataRow

    Dim row As DataRow = DirectCast(Context.Items("CurentUserRow"), DataRow)      <----- is there a typo in this line???

    If row IsNot Nothing Then

    Return row

    End If

    Dim username As String = "Guest"

    row = ExecuteDataRow("SELECT * FROM UploaderUsers WHERE Username={0}", username)

    If row Is Nothing Then

    Dim userid As Integer = ExecuteInt32("INSERT UploaderUsers (UserName) VALUES ({0}) SELECT SCOPE_IDENTITY()", username)

    row = ExecuteDataRow("SELECT * FROM UploaderUsers WHERE UserId={0}", userid)

    End If

    Context.Items("CurentUserRow") = row

    Return row

    End Function

  •  07-28-2008, 4:09 PM 42587 in reply to 42559

    Re: Ajax Uploader and logged in user

    The following code is wrong.

    All the uploaded files will be named as 'Guest' because "If row Is Nothing Then End if" will not be excuted.

    Dim username As String = "Guest"

    row = ExecuteDataRow("SELECT * FROM UploaderUsers WHERE Username={0}", username)

    If row Is Nothing Then

    Dim userid As Integer = ExecuteInt32("INSERT UploaderUsers (UserName) VALUES ({0}) SELECT SCOPE_IDENTITY()", username)

    row = ExecuteDataRow("SELECT * FROM UploaderUsers WHERE UserId={0}", userid)

    End If

    Context.Items("CurentUserRow") = row



    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  07-29-2008, 10:33 AM 42614 in reply to 42587

    Re: Ajax Uploader and logged in user

    This is code out of the AjaxUploader file upload sample.  Do you have a version of the SampleDB that is correct?
     
    Thanks,
     
    Ed
  •  07-29-2008, 3:10 PM 42617 in reply to 42614

    Re: Ajax Uploader and logged in user

    Ed,
     
    In the sample project, all users will be treated as "Guests" for demonstration purpose.

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

View as RSS news feed in XML