当前位置: 首页>>代码示例>>C#>>正文


C# HttpApplication.AddOnBeginRequestAsync方法代码示例

本文整理汇总了C#中System.Web.HttpApplication.AddOnBeginRequestAsync方法的典型用法代码示例。如果您正苦于以下问题:C# HttpApplication.AddOnBeginRequestAsync方法的具体用法?C# HttpApplication.AddOnBeginRequestAsync怎么用?C# HttpApplication.AddOnBeginRequestAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.HttpApplication的用法示例。


在下文中一共展示了HttpApplication.AddOnBeginRequestAsync方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Init

 public void Init(HttpApplication context)
 {
     context.BeginRequest += CreateEventHandler(OnBeginRequest);
     context.EndRequest += CreateEventHandler(OnEndRequest);
     context.AuthenticateRequest += CreateEventHandler(OnAuthenticateRequest);
     context.Error += CreateEventHandler(OnError);
     context.MapRequestHandler += CreateEventHandler(OnMapRequest);
     var asynchelper = new EventHandlerTaskAsyncHelper(OnBeginRequestAsync);
     context.AddOnBeginRequestAsync(asynchelper.BeginEventHandler, asynchelper.EndEventHandler);
 }
开发者ID:grbbod,项目名称:drconnect-jungo,代码行数:10,代码来源:BaseHttpModule.cs

示例2: Init

        public void Init(HttpApplication init)
        {
            var appHandler = AppHandlerSingleton.Instance;

            init.AddOnBeginRequestAsync(
                (sender, args, callback, state) =>
                {
                    var httpContext = ((HttpApplication) sender).Context;
                    return appHandler.BeginProcessRequest(new HttpContextWrapper(httpContext), callback, state);
                },
                appHandler.EndProcessRequest);
        }
开发者ID:bvanderveen,项目名称:gate,代码行数:12,代码来源:Module.cs

示例3: Init

 public void Init(HttpApplication context)
 {
     _context = context;
     context.AddOnBeginRequestAsync(BeginBeginRequest, EndBeginRequest, null);
 }
开发者ID:akhuang,项目名称:Zing,代码行数:5,代码来源:WarmupHttpModule.cs

示例4: Builder

        void IHttpModule.Init(HttpApplication context)
        {
            var applicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            var lines = File.ReadLines(Path.Combine(applicationBase, "config.taco"));

            var builder = new Builder();
            builder.ParseLines(lines);
            var app = builder.ToApp();

            var standardError = Console.OpenStandardError(); //TODO: correct place for default output?

            context.AddOnBeginRequestAsync(
                (sender, e, callback, state) => {
                    var httpApplication = (HttpApplication)sender;
                    var httpContext = httpApplication.Context;
                    var httpRequest = httpContext.Request;
                    var httpResponse = httpContext.Response;
                    var serverVariables = httpRequest.ServerVariables;

                    httpResponse.Buffer = false;

                    var env = serverVariables.AllKeys
                        .ToDictionary(key => key, key => (object)serverVariables[key]);

                    new Environment(env) {
                        Version = new Version(1, 0),
                        UrlScheme = httpRequest.Url.Scheme,
                        Body = new RequestBody(httpRequest.GetBufferlessInputStream()),
                        Errors = standardError,
                        Multithread = true,
                        Multiprocess = false,
                        RunOnce = false,
                        Session = new Session(httpContext.Session),
                        Logger = (eventType, message, exception) => { }, //TODO: any default logger for this host?
                    };

                    var scriptName = httpRequest.ApplicationPath;
                    if (scriptName == "/")
                        scriptName = "";
                    var pathInfo = httpRequest.Url.AbsolutePath;
                    if (pathInfo == "")
                        pathInfo = "/";

                    env["SCRIPT_NAME"] = scriptName;
                    env["PATH_INFO"] = pathInfo.Substring(scriptName.Length);

                    var task = Task.Factory.StartNew(_ => {
                        app.InvokeAsync(env)
                            .Then((status, headers, body) => {
                                httpResponse.StatusCode = status;
                                foreach (var header in Split(headers)) {
                                    httpResponse.AppendHeader(header.Key, header.Value);
                                }
                                var writer = new ResponseBody(
                                    httpResponse.ContentEncoding,
                                    httpResponse.OutputStream.Write,
                                    httpResponse.OutputStream.BeginWrite,
                                    httpResponse.OutputStream.EndWrite);
                                body.ForEach(writer.Write).Then(httpResponse.End);
                            });
                    }, state, TaskCreationOptions.PreferFairness);

                    if (callback != null)
                        task.Finally(() => callback(task));

                    return task;
                },
                ar => ((Task)ar).Wait());
        }
开发者ID:loudej,项目名称:taco,代码行数:69,代码来源:AspNetTacoModule.cs

示例5: Init

        public void Init(HttpApplication init)
        {
            init.AddOnBeginRequestAsync(
                (sender, args, callback, state) =>
                {
                    var taskCompletionSource = new TaskCompletionSource<Action>(state);
                    if (callback != null)
                        taskCompletionSource.Task.ContinueWith(task => callback(task), TaskContinuationOptions.ExecuteSynchronously);

                    var httpContext = ((HttpApplication) sender).Context;
                    var httpRequest = httpContext.Request;
                    var serverVariables = new ServerVariables(httpRequest.ServerVariables);

                    var appRelCurExeFilPat = httpRequest.AppRelativeCurrentExecutionFilePath.Substring(1);

                    var env = new Dictionary<string, object>();
                    new Environment(env)
                    {
                        Version = "1.0",
                        Method = httpRequest.HttpMethod,
                        UriScheme = httpRequest.Url.Scheme,
                        ServerName = serverVariables.ServerName,
                        ServerPort = serverVariables.ServerPort,
                        BaseUri = "",
                        RequestUri = appRelCurExeFilPat + "?" + serverVariables.QueryString,
                        Headers = httpRequest.Headers.AllKeys.ToDictionary(x => x, x => httpRequest.Headers.Get(x)),
                        Body = (next, error, complete) =>
                        {
                            var stream = httpContext.Request.InputStream;
                            var buffer = new byte[4096];
                            var continuation = new AsyncCallback[1];
                            bool[] stopped = {false};
                            continuation[0] = result =>
                            {
                                if (result != null && result.CompletedSynchronously) return;
                                try
                                {
                                    for (;;)
                                    {
                                        if (result != null)
                                        {
                                            var count = stream.EndRead(result);
                                            if (stopped[0]) return;
                                            if (count <= 0)
                                            {
                                                complete();
                                                return;
                                            }
                                            var data = new ArraySegment<byte>(buffer, 0, count);
                                            if (next(data, () => continuation[0](null))) return;
                                        }

                                        if (stopped[0]) return;
                                        result = stream.BeginRead(buffer, 0, buffer.Length, continuation[0], null);
                                        if (!result.CompletedSynchronously) return;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    error(ex);
                                }
                            };
                            continuation[0](null);
                            return () => { stopped[0] = true; };
                        },
                    };
                    Host.Call(
                        env,
                        taskCompletionSource.SetException,
                        (status, headers, body) =>
                        {
                            try
                            {
                                httpContext.Response.Status = status;
                                foreach (var header in headers.SelectMany(kv => kv.Value.Split("\r\n".ToArray(), StringSplitOptions.RemoveEmptyEntries).Select(v => new {kv.Key, Value = v})))
                                {
                                    httpContext.Response.AddHeader(header.Key, header.Value);
                                }
                                if (body == null)
                                {
                                    taskCompletionSource.SetResult(() => httpContext.Response.End());
                                    return;
                                }
                                var stream = httpContext.Response.OutputStream;
                                body(
                                    (data, continuation) =>
                                    {
                                        try
                                        {
                                            if (continuation == null)
                                            {
                                                stream.Write(data.Array, data.Offset, data.Count);
                                                return false;
                                            }
                                            var sr = stream.BeginWrite(data.Array, data.Offset, data.Count, ar =>
                                            {
                                                if (ar.CompletedSynchronously) return;
                                                try
                                                {
                                                    stream.EndWrite(ar);
//.........这里部分代码省略.........
开发者ID:loudej,项目名称:gato,代码行数:101,代码来源:Module.cs

示例6: OnContext

 public void OnContext( HttpApplication application )
 {
    application.AddOnBeginRequestAsync( OnRequestBegun, OnRequestCompleted, application );
 }
开发者ID:code-attic,项目名称:hyperstack,代码行数:4,代码来源:HttpApplicationProxy.cs

示例7: Events_Deny_Unrestricted

		public void Events_Deny_Unrestricted ()
		{
			HttpApplication app = new HttpApplication ();
			app.Disposed += new EventHandler (Handler);
			app.Error += new EventHandler (Handler);
			app.PreSendRequestContent += new EventHandler (Handler);
			app.PreSendRequestHeaders += new EventHandler (Handler);
			app.AcquireRequestState += new EventHandler (Handler);
			app.AuthenticateRequest += new EventHandler (Handler);
			app.AuthorizeRequest += new EventHandler (Handler);
			app.BeginRequest += new EventHandler (Handler);
			app.EndRequest += new EventHandler (Handler);
			app.PostRequestHandlerExecute += new EventHandler (Handler);
			app.PreRequestHandlerExecute += new EventHandler (Handler);
			app.ReleaseRequestState += new EventHandler (Handler);
			app.ResolveRequestCache += new EventHandler (Handler);
			app.UpdateRequestCache += new EventHandler (Handler);

			app.AddOnAcquireRequestStateAsync (null, null);
			app.AddOnAuthenticateRequestAsync (null, null);
			app.AddOnAuthorizeRequestAsync (null, null);
			app.AddOnBeginRequestAsync (null, null);
			app.AddOnEndRequestAsync (null, null);
			app.AddOnPostRequestHandlerExecuteAsync (null, null);
			app.AddOnPreRequestHandlerExecuteAsync (null, null);
			app.AddOnReleaseRequestStateAsync (null, null);
			app.AddOnResolveRequestCacheAsync (null, null);
			app.AddOnUpdateRequestCacheAsync (null, null);

			app.Disposed -= new EventHandler (Handler);
			app.Error -= new EventHandler (Handler);
			app.PreSendRequestContent -= new EventHandler (Handler);
			app.PreSendRequestHeaders -= new EventHandler (Handler);
			app.AcquireRequestState -= new EventHandler (Handler);
			app.AuthenticateRequest -= new EventHandler (Handler);
			app.AuthorizeRequest -= new EventHandler (Handler);
			app.BeginRequest -= new EventHandler (Handler);
			app.EndRequest -= new EventHandler (Handler);
			app.PostRequestHandlerExecute -= new EventHandler (Handler);
			app.PreRequestHandlerExecute -= new EventHandler (Handler);
			app.ReleaseRequestState -= new EventHandler (Handler);
			app.ResolveRequestCache -= new EventHandler (Handler);
			app.UpdateRequestCache -= new EventHandler (Handler);
#if NET_2_0
			app.PostAuthenticateRequest += new EventHandler (Handler);
			app.PostAuthorizeRequest += new EventHandler (Handler);
			app.PostResolveRequestCache += new EventHandler (Handler);
			app.PostMapRequestHandler += new EventHandler (Handler);
			app.PostAcquireRequestState += new EventHandler (Handler);
			app.PostReleaseRequestState += new EventHandler (Handler);
			app.PostUpdateRequestCache += new EventHandler (Handler);

			app.AddOnPostAuthenticateRequestAsync (null, null);
			app.AddOnPostAuthenticateRequestAsync (null, null, null);
			app.AddOnPostAuthorizeRequestAsync (null, null);
			app.AddOnPostAuthorizeRequestAsync (null, null, null);
			app.AddOnPostResolveRequestCacheAsync (null, null);
			app.AddOnPostResolveRequestCacheAsync (null, null, null);
			app.AddOnPostMapRequestHandlerAsync (null, null);
			app.AddOnPostMapRequestHandlerAsync (null, null, null);
			app.AddOnPostAcquireRequestStateAsync (null, null);
			app.AddOnPostAcquireRequestStateAsync (null, null, null);
			app.AddOnPostReleaseRequestStateAsync (null, null);
			app.AddOnPostReleaseRequestStateAsync (null, null, null);
			app.AddOnPostUpdateRequestCacheAsync (null, null);
			app.AddOnPostUpdateRequestCacheAsync (null, null, null);

			app.AddOnAcquireRequestStateAsync (null, null, null);
			app.AddOnAuthenticateRequestAsync (null, null, null);
			app.AddOnAuthorizeRequestAsync (null, null, null);
			app.AddOnBeginRequestAsync (null, null, null);
			app.AddOnEndRequestAsync (null, null, null);
			app.AddOnPostRequestHandlerExecuteAsync (null, null, null);
			app.AddOnPreRequestHandlerExecuteAsync (null, null, null);
			app.AddOnReleaseRequestStateAsync (null, null, null);
			app.AddOnResolveRequestCacheAsync (null, null, null);
			app.AddOnUpdateRequestCacheAsync (null, null, null);

			app.PostAuthenticateRequest -= new EventHandler (Handler);
			app.PostAuthorizeRequest -= new EventHandler (Handler);
			app.PostResolveRequestCache -= new EventHandler (Handler);
			app.PostMapRequestHandler -= new EventHandler (Handler);
			app.PostAcquireRequestState -= new EventHandler (Handler);
			app.PostReleaseRequestState -= new EventHandler (Handler);
			app.PostUpdateRequestCache -= new EventHandler (Handler);
#endif
		}
开发者ID:nobled,项目名称:mono,代码行数:87,代码来源:HttpApplicationCas.cs

示例8: Init

 /// <summary>
 /// Initialises the module.
 /// </summary>
 /// <param name="context">Application context.</param>
 public void Init(HttpApplication context)
 {
     context.BeginRequest += new EventHandler(Context_AuthenticateRequest);
     context.AddOnBeginRequestAsync(AsyncBeginRequest,AsyncBeginRequestEnd);
 }
开发者ID:afrog33k,项目名称:eAd,代码行数:9,代码来源:UploadModule.cs


注:本文中的System.Web.HttpApplication.AddOnBeginRequestAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。