本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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;
}
}
};
}
示例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();
};
}
示例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;
}
示例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();
}
示例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);
}
}
示例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
}
示例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
}
示例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);
}
}
示例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();
}
示例13: Init
public void Init(HttpApplication context)
{
context.Error += context_Error;
context.BeginRequest += context_BeginRequest;
context.EndRequest += context_EndRequest;
context.PostResolveRequestCache += context_PostResolveRequestCache;
}
示例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);
};
}
示例15: EventHandler
void IHttpModule.Init(HttpApplication context)
{
if (UmbracoSettings.UseViewstateMoverModule)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
}