當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。