0

umbraco v 4.7.1(アセンブリバージョン:1.0.4281.20201)を使用していて、global.asaxファイルを拡張する必要があるプロジェクトがあります。

次のことはしないでください

これが私の実装です、

using Project.Umbraco.DependencyInjection;
using Project.Umbraco.IoC;
using Microsoft.Practices.Unity;
using System;
using System.Diagnostics;
using umbraco;

namespace Project.Umbraco.App_Start
{
    public class MyGlobal : Global, IContainerAccessor
    {
        /// 

        /// Returns the IoC container
        /// IContainerAccessor
        /// 

        public IUnityContainer Container
        {
            get
            {
                return MvcUnityContainer.Instance.Container;
            }
        }

        protected override void Application_Start(object sender, EventArgs e)
        {
            base.Application_Start(sender, e);
            Debug.WriteLine("Application start");
        }

        protected override void Application_BeginRequest(object sender, EventArgs e)
        {
            base.Application_BeginRequest(sender, e);
            Debug.WriteLine("Application start");
        }
        //protected void Session_Start(object sender, EventArgs e) {}
        //protected void Application_AuthenticateRequest(object sender, EventArgs e) {}
        //protected void Application_Error(object sender, EventArgs e) {}
        //protected void Session_End(object sender, EventArgs e) {}
        //protected void Application_End(object sender, EventArgs e) {}
    }
}

実装は機能するはずのようですが、これを間違った名前空間などに配置しただけでしょうか?

助けてくれてありがとう

T

4

1 に答える 1

2

Umbraco 4.8.0以降では、App_global.asax.dllは不要になったため、新しいバージョンへのアップグレードを検討することをお勧めします。

ただし、4.7では、次のようなクラスを作成することで、PreApplicationStartメソッドを使用できます。

using System.Linq;
using System.Web.Routing;
using System.Web.Http;
using CustomerName.Extensions;

[assembly: System.Web.PreApplicationStartMethod(typeof(AppStart), "PreStart")]
namespace CustomerName.Extensions
{
    public static class AppStart
    {
        public static void PreStart()
        {
            RouteTable.Routes.MapHttpRoute(
               name: "DefaultApi",
               routeTemplate: "api/{controller}/{id}",
               defaults: new { id = RouteParameter.Optional }
           );
        }
    }
}

もちろん、WebAPIルートを定義する代わりに、DIコードを挿入することもできます。

于 2012-09-09T17:18:39.823 に答える