Advertisement
Guest User

How to solve HTTP 302 error in Uploadify

a guest
Mar 24th, 2012
856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. <script type="text/javascript">
  2. var auth = "<%= IIf(IsNothing(Request.Cookies(FormsAuthentication.FormsCookieName)),String.Empty,Request.Cookies(FormsAuthentication.FormsCookieName).Value) %>";
  3. var ASPSESSID = "<%=Session.SessionID%>";
  4.  
  5. $(window).load(
  6. function () {
  7.  
  8. alert(auth);
  9. $("#FileUpload1").fileUpload({
  10. 'uploader': 'scripts/uploader.swf',
  11. 'cancelImg': 'image/cancel.png',
  12. 'buttonText': 'Click to Choose Document',
  13. 'script': 'UploadDocument.aspx',
  14. //'scriptData': { 'ASPSESSID': ASPSESSID, 'AUTHID': auth },
  15. 'scriptData': { 'token': auth },
  16. 'folder': 'Documents',
  17. 'hideButton': false,
  18. //'wmode': 'transparent',
  19. 'multi': true,
  20. 'auto': false
  21. });
  22. }
  23. );
  24. </script>
  25.  
  26. Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
  27. ' Fires at the beginning of each request
  28. Try
  29. Dim session_param_name = "ASPSESSID"
  30. Dim session_cookie_name = "ASP.NET_SessionId"
  31.  
  32. If Not HttpContext.Current.Request.Form(session_param_name) Is Nothing Then
  33. UpdateCookie(session_cookie_name, HttpContext.Current.Request.Form(session_param_name))
  34. ElseIf Not HttpContext.Current.Request.QueryString(session_param_name) Is Nothing Then
  35. UpdateCookie(session_cookie_name, HttpContext.Current.Request.QueryString(session_param_name))
  36. End If
  37. Catch ex As Exception
  38. End Try
  39.  
  40.  
  41. Try
  42. Dim auth_param_name = "AUTHID"
  43. Dim auth_cookie_name = FormsAuthentication.FormsCookieName
  44.  
  45. If Not HttpContext.Current.Request.Form(auth_param_name) Is Nothing Then
  46. UpdateCookie(auth_cookie_name, HttpContext.Current.Request.Form(auth_param_name))
  47. ElseIf Not HttpContext.Current.Request.QueryString(auth_param_name) Is Nothing Then
  48. UpdateCookie(auth_cookie_name, HttpContext.Current.Request.QueryString(auth_param_name))
  49. End If
  50. Catch ex As Exception
  51. End Try
  52.  
  53.  
  54. End Sub
  55.  
  56. Context.Response.ContentType = "text/plain"
  57. Context.Response.Expires = -1
  58.  
  59. Dim token As String = Context.Request.Params("token")
  60. 'Dim token As String
  61.  
  62. 'If IsNothing(Request.Cookies(FormsAuthentication.FormsCookieName)) Then
  63. ' token = String.Empty
  64. 'Else
  65. ' token = Request.Cookies(FormsAuthentication.FormsCookieName).Value
  66. 'End If
  67.  
  68.  
  69.  
  70. Dim ticket As FormsAuthenticationTicket = FormsAuthentication.Decrypt(token)
  71. If ticket IsNot Nothing Then
  72. Dim identity = New FormsIdentity(ticket)
  73. If identity.IsAuthenticated Then
  74. Try
  75. Dim postedFile As HttpPostedFile = Context.Request.Files("")
  76.  
  77. Dim tempStr As String = Context.Request.QueryString("")
  78.  
  79. Dim savepath As String = ""
  80. Dim tempPath As String = ""
  81. tempPath = System.Configuration.ConfigurationManager.AppSettings("FolderPath")
  82. savepath = Context.Server.MapPath(tempPath)
  83. Dim filename As String = postedFile.FileName
  84. Dim filetype As String = postedFile.ContentType
  85.  
  86. If Not Directory.Exists(savepath) Then
  87. Directory.CreateDirectory(savepath)
  88. End If
  89.  
  90. postedFile.SaveAs(savepath & "" & filename)
  91.  
  92. Context.Response.Write(savepath & "" & filename)
  93. Context.Response.StatusCode = 200
  94.  
  95. Catch ex As Exception
  96. Context.Response.Write("Error: " & ex.Message)
  97. End Try
  98. End If
  99. End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement