【发布时间】:2015-07-02 16:25:48
【问题描述】:
我想在 Umbraco 中触发 BeginRequest 事件,但它不起作用。其余代码运行良好。
public class ApplicationEventHandler : IApplicationEventHandler
{
public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { }
public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { }
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
umbracoApplication.BeginRequest += umbracoApplication_BeginRequest;
BundleConfig.RegisterBundles(BundleTable.Bundles);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
}
void umbracoApplication_BeginRequest(object sender, EventArgs e)
{
// Create HttpApplication and HttpContext objects to access
// request and response properties.
UmbracoApplicationBase application = (UmbracoApplicationBase)sender;
HttpContext context = application.Context;
if (context.Response.Cookies[Const.LANGUAGE_COOKIE_NAME] == null)
{
context.Response.Cookies.Add(new HttpCookie(Const.LANGUAGE_COOKIE_NAME, Thread.CurrentThread.CurrentUICulture.Name));
return;
}
//cookie exists already
else
{
//if no 404
if (UmbracoContext.Current.PublishedContentRequest != null && !UmbracoContext.Current.PublishedContentRequest.Is404)
{
//cookie value different than the current thread: user switched language.
if (context.Response.Cookies[Const.LANGUAGE_COOKIE_NAME].Value != Thread.CurrentThread.CurrentUICulture.Name)
{
//we set the cookie
context.Response.Cookies[Const.LANGUAGE_COOKIE_NAME].Value = Thread.CurrentThread.CurrentUICulture.Name;
}
}
}
}
}
你知道它为什么不工作吗? 我正在使用 umbraco 7,本地 IIS(不是 express),我无法在 umbracoApplication_BeginRequest 函数中记录消息。
【问题讨论】:
标签: c# asp.net umbraco umbraco7