开发者

ASP.NET How to process only 1 HTTP handler at a time from a specified user?

I have the next problem: I need to开发者_JS百科 process only 1 request at a time from each user. Lets assume that server identifies each user be UserID, sent in query string. How can make the server work the way like FIFO (do not start processing next request until the previous is fully processed)? Should I use the named mutexes inside HTTP handler and assign the name to mutex by UserID?

Thanks in advance, Valentin


When the first request comes, Set a flag in Session. Reset this flag only after the processing of the first request completes.

If the user requests again, without having the first request completed, just reject the request by returning from ProcessRequest() without any further line of code executed. Additionally you can reply the user back with appropriate status-message.

EDIT

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.SessionState;

namespace MyHandlers
{
    public class MyHttpHander : IHttpHandler,IRequiresSessionState
    {
        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            context.Response.Write("<h1><b>HttpHandler Test</b></h1>");
            context.Session["Test"] = "Invoke a session in HttpHandler.";
            context.Response.Write(context.Session["Test"]+"<br>");
            context.Response.Write("<a href='HttpHandlerCsharp.aspx'><b>return</b></a>");
        }
    }
} 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜