zoukankan      html  css  js  c++  java
  • OrchardHUN.TrainingDemo 学习记录(1)Controller中,使用Orchard API

    1、Controller中,使用Orchard API.例子:

    using Orchard;
    using Orchard.Localization;
    using Orchard.Logging;
    using Orchard.Mvc;
    using Orchard.UI.Notify;
    using System.Web.Mvc;
    
    namespace OrchardHUN.TrainingDemo.Controllers
    {
        public class DependencyInjectionController :Controller
        {
            private readonly INotifier _notifier;
    
            private readonly IWorkContextAccessor _wca;
            private readonly IHttpContextAccessor _hca;
            public Localizer T { get; set; }
    
            public ILogger Logger { get; set; }
    
            public DependencyInjectionController(INotifier notifier, IWorkContextAccessor wca, IHttpContextAccessor hca)
            {
                _notifier = notifier;
                _wca = wca;
                _hca = hca;
                T = NullLocalizer.Instance;
                Logger = NullLogger.Instance;
            }
            public ActionResult NotifyMe()
            {
                //当前用户
                var currentUser = _wca.GetContext().CurrentUser;
                //当前用户名称
                var currentUserName = currentUser == null ? "<subject name here>" : currentUser.UserName;
                //当前URL
                var currentUrl = _hca.Current().Request.Url.ToString();
                //在用户界面出现消息
    
                _notifier.Information(T("Please continue testing. -- Subject name: {0}; Subject location: {1}", currentUserName, currentUrl));
    
               //在日志中写入消息,消息存放在以日期为单位,类型为error的信息文本文件中 App_Data/Logs!
                Logger.Error("Test subject notified.");
    
                // We redirect to the first controller here but the notification will still be displayed. This is because notifications
                // are meant to provide a way to interact with the user even after a redirect. Of course after they're shown once 
                // notifications will be dismissed.
                return RedirectToAction("Index", "YourFirstOrchard");
            }
        }
    }
    
  • 相关阅读:
    tp.c
    trace
    一致性哈希算法
    update_dctcp_alpha
    dctcp-ns2-patch
    C++ inheritance: public, private. protected ZZ
    C++ virtual inheritance ZZ
    C++ 类对象的初始化顺序 ZZ
    C++ inheritance examples
    classifier.cc-recv() [ns2.35]
  • 原文地址:https://www.cnblogs.com/zsanhong/p/3086746.html
Copyright © 2011-2022 走看看