Uploadify를 사용하여 ASP.NET에서 일부 이미지를 업로드하고 있습니다.
ASP.NET에서 Response.WriteFile()
을 사용하여 업로드 결과를 다시 JavaScript로 반환합니다. 설명서에 명시된대로 onAllComplete
이벤트를 사용하여 ASP.NET의 응답 문자열을 확인합니다.Uploadify 응답 값은 항상 ASP.NET에서 정의되지 않습니다.
alert(response);
은 JavaScript에서 항상 정의되지 않습니다. 아래
자바 스크립트 코드 :
$(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);
}
});
});
ASP.NET 코드 아래; FormsAuthenticationTicket
오브젝트
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");
}
}
이유 파이어 폭스와 Uploadify를 사용할 때 비록 인증 쿠키를 전달하는 것이다.
Response.Write
이 onAllComplete
이벤트로 값을 반환하는 많은 예제를 보았습니다. 하지만 내가 얻는 것은 모두 정의되지 않았습니다. Context.Response.Write
, this.Response.Write
, HttpContext.Current.Response.Write
을 사용해 보았습니다. 그들은 모두 정의되지 않은 상태로 돌아옵니다.
도움을 주시면 감사하겠습니다. 감사합니다.
중단 점을 설정할 때 (identity.IsAuthenticated) 중단 점이 맞았습니까? – Tony
올바른 실행 흐름을 보장하기 위해 시작하는 '기본'응답 .NET 코드를 추가합니다. 귀하의 디버깅은 아직 모든 옵션을 배제하지 않았습니다. – cusimar9
예, identity.IsAuthenticated는 true를 반환하고 이미지 저장이 수행됩니다. 또한 Response.Write ("test"); .NET 코드가 존재하기 전에 라인이 실제로 손상됩니다. – Sivakanesh