Currently, I am utilizing Uploadify to upload a series of images with the assistance of ASP.NET.
To transmit the outcome of the upload back to JavaScript, I have employed Response.WriteFile()
in ASP.NET.
I am adhering to the guidance provided in the documentation by utilizing the onAllComplete
event to inspect the response string originating from ASP.NET.
The predicament appears to be that the alert(response);
action constantly yields an undefined result in JavaScript.
The JavaScript code is as follows:
$(document).ready(function() {
var auth = "<% = Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value %>";
$('#btnUpdateProfileImg').uploadify({
'uploader': '../script/uploadify/uploadify.swf',
'script': '../uploadprofimg.aspx',
'cancelImg': '../script/uploadify/cancel.png',
'folder': '../script/uploadify',
'scriptData': { 'id': $(this).attr("id"), 'token': auth },
'onAllComplete': function(event, queueID, fileObj, response, data) {
alert(response);
}
});
});
The ASP.NET code can be seen below:
protected void Page_Load(object sender, EventArgs e)
{
try
{
string token = Request.Form["token"].ToString();
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(token);
if (ticket != null)
{
var identity = new FormsIdentity(ticket);
if (identity.IsAuthenticated)
{
HttpPostedFile hpFile = Request.Files["ProfileImage"];
string appPath = HttpContext.Current.Request.ApplicationPath;
string fullPath = HttpContext.Current.Request.MapPath(appPath) + @"\avatar\";
hpFile.SaveAs(Server.MapPath("~/" + uniqName));
Response.ContentType = "text/plain";
Response.Write("test");
}
}
}
catch (Exception ex)
{
Response.Write("test");
}
}
The utilization of the FormsAuthenticationTicket
object aims to effectively carry over the authentication cookie during the usage of Uploadify in Firefox and similar browsers.
I have encountered numerous instances where Response.Write
furnishes a return value to the onAllComplete
event. Nevertheless, my situation only results in undefined feedback.
I made attempts with Context.Response.Write
, this.Response.Write
, and
HttpContext.Current.Response.Write
. Unfortunately, they all delivered an undetermined output.
Your assistance on this matter would be greatly appreciated. Thank you.