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


C# Web.HttpApplication类代码示例

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


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

示例1: AsyncHandler

		public AsyncHandler(AsyncCallback callback, FluorineGateway gateway, HttpApplication httpApplication, Object state) {
			_gateway = gateway;
			_callback = callback;
			_httpApplication = httpApplication;
			_state = state;
			_completed = false;
		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:7,代码来源:AsyncHandler.cs

示例2: Init

        public void Init(HttpApplication context)
        {
            if (context == null) { throw new ArgumentNullException("context"); }

            context.BeginRequest += new EventHandler(context_BeginRequest);
            context.EndRequest += new EventHandler(context_EndRequest);
        }
开发者ID:jrgcubano,项目名称:zetbox,代码行数:7,代码来源:ZetboxContextManagerModule.cs

示例3: OnApplicationEnd

        /// <summary>
        /// Called when the host application stops.
        /// </summary>
        /// <param name="application">The host application.</param>
        public void OnApplicationEnd(HttpApplication application)
        {
            Logger.Info("Better CMS host application stopped.");

            // Notify.
            ApiContext.Events.OnHostStop(application);
        }
开发者ID:tkirda,项目名称:BetterCMS,代码行数:11,代码来源:DefaultCmsHost.cs

示例4: Init

        public void Init(HttpApplication context)
        {
            context.AuthenticateRequest += (sender, e) =>
            {
                HttpContext httpContext = ((HttpApplication)sender).Context;

                dynamic signedRequest = FacebookRequestHelpers.GetSignedRequest(
                    new HttpContextWrapper(httpContext),
                    rawSignedRequest =>
                    {
                        FacebookConfiguration config = GlobalFacebookConfiguration.Configuration;
                        FacebookClient client = config.ClientProvider.CreateClient();
                        return client.ParseSignedRequest(rawSignedRequest);
                    });

                if (signedRequest != null)
                {
                    string userId = signedRequest.user_id;
                    if (!String.IsNullOrEmpty(userId))
                    {
                        ClaimsPrincipal principal = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.NameIdentifier, userId) }));
                        Thread.CurrentPrincipal = principal;
                        httpContext.User = principal;
                    }
                }
            };
        }
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:27,代码来源:FacebookAuthenticationModule.cs

示例5: Init

        public void Init(HttpApplication context)
        {
            context.BeginRequest += (sender, e) =>
            {
                var request = ((HttpApplication)sender).Request;
                //TODO: By default only local requests are profiled, optionally you can set it up
                //  so authenticated users are always profiled
                //if (request.IsLocal) { MiniProfiler.Start(); }
            //                MiniProfiler.Start();
            };

            // TODO: You can control who sees the profiling information
            /*
            context.AuthenticateRequest += (sender, e) =>
            {
                if (!CurrentUserIsAllowedToSeeProfiler())
                {
                    MvcMiniProfiler.MiniProfiler.Stop(discardResults: true);
                }
            };
            */

            context.EndRequest += (sender, e) =>
            {
            //                MiniProfiler.Stop();
            };
        }
开发者ID:dennisdoomen,项目名称:specflowdemo,代码行数:27,代码来源:MiniProfiler.cs

示例6: HostInitialization

        private static IWebHost HostInitialization(HttpApplication application)
        {
            var kernelBuilder = new KernelBuilder();

            kernelBuilder.UseCaching(c => c.UseMemoryCache());
            kernelBuilder.UseLogging(c => c.UseNLog());
            kernelBuilder.UseWeb(c => c.EnableMvc().EnableSecurity());
            kernelBuilder.UseData(c =>
            {
                c.UseEntityFramework();
                c.EnableMvcFilterTransaction();

                //如果开启了EntityFramework的自动迁移则不启动数据迁移。
                var automaticMigrationsEnabled = ConfigurationManager.AppSettings["Data.EntityFramework.AutomaticMigrationsEnabled"];
                if (!string.Equals(automaticMigrationsEnabled, "true", StringComparison.OrdinalIgnoreCase))
                    c.EnableDataMigrators();
            });

            kernelBuilder.UseResources();

            var container = kernelBuilder.Build();

            var host = container.Resolve<IWebHost>();

            host.Initialize();
            host.BeginRequest();
            host.EndRequest();

            return host;
        }
开发者ID:coderen,项目名称:RabbitCMS,代码行数:30,代码来源:Global.asax.cs

示例7: RequestAuthentication

 private void RequestAuthentication(HttpApplication app)
 {
     ApplicationServices appServices = new ApplicationServices();
     app.Response.AppendHeader("WWW-Authenticate", String.Format("Basic realm=\"{0}\"", appServices.Realm));
     app.Response.StatusCode = 401;
     app.CompleteRequest();
 }
开发者ID:mehedi09,项目名称:GridWork,代码行数:7,代码来源:ExportAuthenticationModule.cs

示例8: PropagatesCallerInfoThroughExceptionDuringSignaling

        public void PropagatesCallerInfoThroughExceptionDuringSignaling()
        {
            var module = new TestErrorLogModule();
            var mocks = new { Context = new Mock<HttpContextBase> { DefaultValue = DefaultValue.Mock } };
            using (var app = new HttpApplication())
            {
                var context = mocks.Context.Object;
                var callerInfo = new CallerInfo("foobar", "baz.cs", 42);
                var exception = new Exception();
                IDictionary actualData = null;
                module.LogExceptionOverride = (e, _) => actualData = new Hashtable(e.Data);
                
                module.OnErrorSignaled(app, new ErrorSignalEventArgs(exception, context, callerInfo));

                Assert.Equal(0, exception.Data.Count);
                Assert.NotNull(actualData);
                Assert.Equal(1, actualData.Count);
                var actualCallerInfo = (CallerInfo) actualData.Cast<DictionaryEntry>().First().Value;
                Assert.Same(callerInfo, actualCallerInfo);

                module.LogExceptionOverride = delegate { throw new TestException(); };

                Assert.Throws<TestException>(() => module.OnErrorSignaled(app, new ErrorSignalEventArgs(exception, context, callerInfo)));
                Assert.Equal(0, exception.Data.Count);
            }
        }
开发者ID:ramsenthil18,项目名称:elmah,代码行数:26,代码来源:ErrorLogModuleTests.cs

示例9: FindCacheProvider

		OutputCacheProvider FindCacheProvider (HttpApplication app)
		{				
#if NET_4_0
			HttpContext ctx = HttpContext.Current;
			if (app == null) {
				app = ctx != null ? ctx.ApplicationInstance : null;

				if (app == null)
					throw new InvalidOperationException ("Unable to find output cache provider.");
			}

			string providerName = app.GetOutputCacheProviderName (ctx);
			if (String.IsNullOrEmpty (providerName))
				throw new ProviderException ("Invalid OutputCacheProvider name. Name must not be null or an empty string.");

			OutputCacheProvider ret = OutputCache.GetProvider (providerName);
			if (ret == null)
				throw new ProviderException (String.Format ("OutputCacheProvider named '{0}' cannot be found.", providerName));

			return ret;
#else
			if (provider == null)
				provider = new InMemoryOutputCacheProvider ();
			
			return provider;
#endif
		}
开发者ID:nlhepler,项目名称:mono,代码行数:27,代码来源:OutputCacheModule.cs

示例10: Init

        public void Init(HttpApplication context)
        {
            //注册对于全局错误的记录
            context.Error += OnError;

            #region 记录UnhandledException

            //使用Double-Check机制保证在多线程并发下只注册一次UnhandledException处理事件
            if (!hasInitilized)
            {
                lock (syncRoot)
                {
                    if (!hasInitilized)
                    {
                        //1. 按照.net的习惯,依然首先将该内容写入到系统的EventLog中
                        string webenginePath = Path.Combine(RuntimeEnvironment.GetRuntimeDirectory(), "webengine.dll");
                        //通过webengine.dll来查找asp.net的版本,eventlog的名称由asp.net+版本构成
                        if (!File.Exists(webenginePath))
                        {
                            throw new Exception(String.Format(CultureInfo.InvariantCulture, "Failed to locate webengine.dll at '{0}'.  This module requires .NET Framework 2.0.", webenginePath));
                        }

                        FileVersionInfo ver = FileVersionInfo.GetVersionInfo(webenginePath);
                        eventSourceName = string.Format(CultureInfo.InvariantCulture, "ASP.NET {0}.{1}.{2}.0", ver.FileMajorPart, ver.FileMinorPart, ver.FileBuildPart);

                        if (!EventLog.SourceExists(eventSourceName))
                        {
                            throw new Exception(String.Format(CultureInfo.InvariantCulture, "There is no EventLog source named '{0}'. This module requires .NET Framework 2.0.", eventSourceName));
                        }

                        //在出现问题后将内容记录下来
                        AppDomain.CurrentDomain.UnhandledException += (o, e) =>
                                                                          {
                                                                              if (Interlocked.Exchange(ref unhandledExceptionCount, 1) != 0)
                                                                                  return;

                                                                              string appId = (string)AppDomain.CurrentDomain.GetData(".appId");
                                                                              appId = appId ?? "No-appId";

                                                                              Exception currException;
                                                                              StringBuilder sb = new StringBuilder();
                                                                              sb.AppendLine(appId);
                                                                              for (currException = (Exception)e.ExceptionObject; currException != null; currException = currException.InnerException)
                                                                              {
                                                                                  sb.AppendFormat("{0}\n\r", currException.ToString());
                                                                                  _log.Error(currException);
                                                                              }

                                                                              EventLog eventLog = new EventLog { Source = eventSourceName };
                                                                              eventLog.WriteEntry(sb.ToString(), EventLogEntryType.Error);
                                                                          };

                        //初始化后设置该值为true保证不再继续注册事件
                        hasInitilized = true;
                    }
                }
            }

            #endregion
        }
开发者ID:huayumeng,项目名称:ytoo.service,代码行数:60,代码来源:GlobalErrorHandlerModule.cs

示例11: Init

		/// <summary>
		/// Initializes a module and prepares it to handle requests.
		/// </summary>
		/// <param name="context">An <see cref="T:System.Web.HttpApplication"></see> that provides access to the methods,
		/// properties, and events common to all application objects within an ASP.NET application </param>
		public void Init(HttpApplication context)
		{
			if (!IoC.IsInitialized)
			{
				InitializeContainer(this);
			}
		}
开发者ID:agross,项目名称:graffiti-usergroups,代码行数:12,代码来源:IoCModule.cs

示例12: JsonResponse

 protected static void JsonResponse(HttpApplication httpApplication, string data)
 {
     var response = httpApplication.Response;
     response.Write(data);
     response.AddHeader("Content-Type", "application/json");
     httpApplication.CompleteRequest();
 }
开发者ID:RobertTheGrey,项目名称:Glimpse,代码行数:7,代码来源:GlimpseResponder.cs

示例13: Init

 public void Init(HttpApplication context)
 {
     context.Error += context_Error;
     context.BeginRequest += context_BeginRequest;
     context.EndRequest += context_EndRequest;
     context.PostResolveRequestCache += context_PostResolveRequestCache;
 }
开发者ID:leloulight,项目名称:Magicodes.NET,代码行数:7,代码来源:CoreModule.cs

示例14: Init

 /// <summary>
 /// Initializes a module and prepares it to handle requests.
 /// </summary>
 /// <param name="context">An <see cref="T:System.Web.HttpApplication" /> that provides access to the methods, properties, and events common to all application objects within an ASP.NET application</param>
 public void Init(HttpApplication context)
 {
     context.EndRequest += (sender, e) =>
     {
         PerWebRequestContainerProvider.DisposeCurrentScope(sender, e);
     };
 }
开发者ID:juancarlospalomo,项目名称:tantumcms,代码行数:11,代码来源:PerWebRequestLifetimeModule.cs

示例15: EventHandler

 void IHttpModule.Init(HttpApplication context)
 {
     if (UmbracoSettings.UseViewstateMoverModule)
     {
         context.BeginRequest += new EventHandler(context_BeginRequest);
     }
 }
开发者ID:elrute,项目名称:Triphulcas,代码行数:7,代码来源:viewstateMoverModule.cs


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