Archive for the ‘Uploadify’ Category
Uploadify ile Firefox upload problemi
Uploadify dosya yüklemesi için kullandığımız en güzel araçlardan biri. Ancak geçen gün bu sistemle dosya yüklemesi yaparken bir problem ile karşılaştım. Yükleme işlemi başlamadan HTTP 302 hatası veriyordu. Daha doğrusu bu hata değil biliyorsunuz. Sistemde session cookie’si bulunamadığı için bizi login sayfasına yönlendiren bir HTTP geri dönüş değeri. Bu durum ile ilgili internette bir araştırma yaptım ve bunun flash plugin’lerinden kaynaklanan bir problem olduğunu öğrendim. Sorun tam olarak şu idi, flash internet explorer dışındaki plug’inlerinde browser cookie’lerini kullanmıyordu. Yani siz siteye login oldunuz, gerekli bütün işlemler ve cookie’ler browser’a yüklendi, ancak bu durumdan sonra flash ile site üzerine bir dosya göndermeye kalktığınızda o zaman flash browser’daki cookie’leri sunucuya göndermediği için flash’ın bu isteği sunucu tarafından anonim bir istek gibi algılanıp, login sayfasına yönlendirilerek sonlandırılıyor.
Tamam sorunu anladık, ama nasıl çözeceğiz. Ben uploadify kullandığım için onun için bir çözüm aradım ve şu linkteki çözümü buldum : http://stackoverflow.com/questions/1729179/uploadify-session-and-authentication-with-asp-net-mvc
Burada sevgili arkadaşımız flash’ın cookie’yi alamaması dolayısıyla cookie’de giden bilgiyi post verisi içerisine ekleyip, bu şekilde bilgiyi karşıya iletmekte. böylece cookie yok ise bu bilgi ile server flash istemcisini tanımakta. güzel bir çözüm bende bu çözümü aşağıda paylaşıyorum :
önce uploadify tanımımızda bazı bilgi eklemeleri yapmamız gerekiyor :
<script>
var auth = "<% = Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value %>";
var ASPSESSID = "<%= Session.SessionID %>";
$("#uploadifyLogo").uploadify({
...
scriptData: { ASPSESSID: ASPSESSID, AUTHID: auth }
});
Sonrada global.asax dosyasına aşağıdaki kodu eklemeliyiz :
protected void Application_BeginRequest(object sender, EventArgs e)
{
/* we guess at this point session is not already retrieved by application so we recreate cookie with the session id... */
try
{
string session_param_name = "ASPSESSID";
string session_cookie_name = "ASP.NET_SessionId";
if (HttpContext.Current.Request.Form[session_param_name] != null)
{
UpdateCookie(session_cookie_name, HttpContext.Current.Request.Form[session_param_name]);
}
else if (HttpContext.Current.Request.QueryString[session_param_name] != null)
{
UpdateCookie(session_cookie_name, HttpContext.Current.Request.QueryString[session_param_name]);
}
}
catch
{
}
try
{
string auth_param_name = "AUTHID";
string auth_cookie_name = FormsAuthentication.FormsCookieName;
if (HttpContext.Current.Request.Form[auth_param_name] != null)
{
UpdateCookie(auth_cookie_name, HttpContext.Current.Request.Form[auth_param_name]);
}
else if (HttpContext.Current.Request.QueryString[auth_param_name] != null)
{
UpdateCookie(auth_cookie_name, HttpContext.Current.Request.QueryString[auth_param_name]);
}
}
catch
{
}
}
private void UpdateCookie(string cookie_name, string cookie_value)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);
if (null == cookie)
{
cookie = new HttpCookie(cookie_name);
}
cookie.Value = cookie_value;
HttpContext.Current.Request.Cookies.Set(cookie);
}
böylece problem çözülür.
Ayrıca başka bir kaynakta MVC tarafındaki çözüm anlatılmış: http://www.uploadify.com/forums/discussion/6494/problem-with-uploadify-the-upload-does-not-start/p1
