开发者

Session Timeout Issue in ASP.Net MVC

开发者 https://www.devze.com 2023-01-23 07:02 出处:网络
In my application user upload movies and the size of movies can be around 100MB or more. For this reason im doubtful that if any user have a slow connection it could take hour开发者_运维问答s and if i

In my application user upload movies and the size of movies can be around 100MB or more. For this reason im doubtful that if any user have a slow connection it could take hour开发者_运维问答s and if it takes so much time then my application session will be expired. What should i do to cater this issue? My application is on ASP.Net MVC2 with C# and hosted on Windows server 2008


Fraz,

I don't know if you have javascript enabled in your app or not. if you do, you could trigger a setInterval method UNTIL the movie has succesfully uploaded (i.e. on completion of the upload, trigger the $ajax complete function to stop the time.

anyway, here's the rough idea:

javascript - called inside the javascript upload function:

function keepMeAlive(imgName) {
    myImg = document.getElementById(imgName);
    if (myImg) myImg.src = myImg.src.replace(/\?.*$/, '?' + Math.random());
}
callbackID = window.setInterval("keepMeAlive('keepAliveIMG')", 100000);

html (just any old image in the document):

<img id="keepAliveIMG" width="1" height="1" src="http://www.some.url/someimg.gif?" />

in the image complete function, add:

clearInterval(callbackID);

also, see:

http://www.dotnetcurry.com/ShowArticle.aspx?ID=453&AspxAutoDetectCookieSupport=1

you could off course append headers to the action that you 'hit' when you upload the movie. i.e. along the lines of (*disclaimer - untested *!!):

// don't know what your action signiture is like
public ActionResult AddMovie()
{
    Response.AddHeader("Refresh", Convert.ToString(((Session.Timeout * 60) - 10)));
    return PartialView("UpdateInProgress");
}

then inside the page, have a div that gets updated with the partialview (UpdateInProgress) at a set interval. Of course, possibly will update the entire page, rather than just the discreet div but you'll hopefully be able to get an idea of the possibilities.

see:

http://tech.tiffanyandjeremy.com/Articles/Reusable-embedded-keep-session-alive-with-HtmlHelper-for-ASP-NET-MVC-1-0-csharp

or:

http://naspinski.net/post/Automatically-refresh-your-users-Session-behind-the-scenes-using-jQuery-and-AspNet.aspx

either appraoch is viable, tho i 'prefer' the 2nd one as it's slightly 'cleaner'

just a few ideas!! :)

0

精彩评论

暂无评论...
验证码 换一张
取 消