当前位置: 首页>>代码示例>>C#>>正文


C# IControllerContext类代码示例

本文整理汇总了C#中IControllerContext的典型用法代码示例。如果您正苦于以下问题:C# IControllerContext类的具体用法?C# IControllerContext怎么用?C# IControllerContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IControllerContext类属于命名空间,在下文中一共展示了IControllerContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnAfterRendering

 protected override void OnAfterRendering(IEngineContext context, IController controller,
                                          IControllerContext controllerContext){
     var mvc = MvcContext.Create((Controller) controller);
     var logname = acl.token(mvc).Replace("/", ".").Substring(1);
     var log = logger.get(logname);
     log.info(() => myapp.usrName + "\t\tAFTER_RENDER:\t" + acl.token(mvc));
 }
开发者ID:Qorpent,项目名称:comdiv.oldcore,代码行数:7,代码来源:LogFilter.cs

示例2: AuthorizeContext

        public bool AuthorizeContext(IControllerContext controllerContext, IController controller) {
            //ОБЩАЯ ПОЛИТИКА - ОТКРЫТОСТЬ ДЕЙСТВИЯ

            // сперва проверим не админ ли сам пользователь
            var usr = myapp.usr;
            if(myapp.roles.IsAdmin(usr)) return true; //админам можно
            
            // потом проверим не назначены ли пользователю спец-права на данное действие или контроллер
            var denyspecialrole = string.Format("DENY_{0}_{1}", controllerContext.Name, controllerContext.Action).ToUpper();
            if (myapp.roles.IsInRole(usr, denyspecialrole)) return false;
            var allowspecialrole = string.Format("ALLOW_{0}_{1}", controllerContext.Name, controllerContext.Action).ToUpper();
            if (myapp.roles.IsInRole(usr, allowspecialrole)) return true;
            var denycontrollerrolename = string.Format("DENY_{0}", controllerContext.Name).ToUpper();
            if (myapp.roles.IsInRole(usr, denycontrollerrolename)) return false;
            var allowcontrollerrolename = string.Format("ALLOW_{0}", controllerContext.Name).ToUpper();
            if (myapp.roles.IsInRole(usr, allowcontrollerrolename)) return true;

            //потом проверяем по атрибутам ролей
            IEnumerable<string> roles = getroles(controller, controllerContext);
            if (roles.Count() != 0) {
                if (roles.All(x => !myapp.roles.IsInRole(usr, x))) return false;
            }

            //если доехали до сюда, значит ошибок авторизации не было, значит дозволим выполнение
            return true;
        }
开发者ID:Qorpent,项目名称:comdiv.oldcore,代码行数:26,代码来源:AuthorizeFilter.cs

示例3: CalculateParamPoints

 /// <summary>
 ///             Calculates the param points. Implementers should return value equals or greater than
 ///             zero indicating whether the parameter can be bound successfully. The greater the value (points)
 ///             the more successful the implementation indicates to the framework
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="controller">The controller.</param>
 /// <param name="controllerContext">The controller context.</param>
 /// <param name="parameterInfo">The parameter info.</param>
 /// <returns>
 /// </returns>
 public int CalculateParamPoints(IEngineContext context, IController controller, IControllerContext controllerContext, ParameterInfo parameterInfo)
 {
     var token = context.Request[parameterName];
     if (CanConvert(parameterInfo.ParameterType, token))
         return 10;
     return 0;
 }
开发者ID:kenegozi,项目名称:openuni,代码行数:18,代码来源:BindFromAttribute.cs

示例4: Render

        /// <summary>
        /// Create a view.
        /// </summary>
        /// <param name="context">Context to render</param>
        public void Render(IControllerContext context, IViewData viewData, TextWriter writer)
        {
            string layoutName;
            if (context.LayoutName != null)
                layoutName = context.LayoutName;
            else
            {
                var controllerName = context.ControllerUri.TrimEnd('/');
                int pos = controllerName.LastIndexOf('/');
                layoutName = context.ControllerUri;
                layoutName += pos == -1
                                  ? controllerName + ".haml"
                                  : controllerName.Substring(pos + 1) + ".haml";

                if (!MvcServer.CurrentMvc.ViewProvider.Exists(layoutName))
                    layoutName = "Shared/Application.haml";
            }

            string viewPath = context.ViewPath + ".haml";


            CompiledTemplate template = _templateEngine.Compile(new List<string> {layoutName, viewPath},
                                                                typeof (NHamlView));

            var instance = (NHamlView)template.CreateInstance();
            instance.ViewData = viewData;
            instance.Render(writer);
        }
开发者ID:oblivious,项目名称:Oblivious,代码行数:32,代码来源:NHamlViewEngine.cs

示例5: Init

        public void Init()
        {
            mocks = new MockRepository();
            factory = new SparkViewFactory();
            engineContext = mocks.CreateMock<IEngineContext>();
            server = new MockServerUtility();
            request = mocks.CreateMock<IRequest>();
            response = mocks.CreateMock<IResponse>();

            controller = mocks.CreateMock<IController>();
            controllerContext = mocks.CreateMock<IControllerContext>();
            routingEngine = mocks.CreateMock<IRoutingEngine>();
            output = new StringWriter();
            helpers = new HelperDictionary();

            propertyBag = new Dictionary<string, object>();
            flash = new Flash();
            session = new Dictionary<string, object>();
            requestParams = new NameValueCollection();
            contextItems = new Dictionary<string, object>();


            SetupResult.For(engineContext.Server).Return(server);
            SetupResult.For(engineContext.Request).Return(request);
            SetupResult.For(engineContext.Response).Return(response);
            SetupResult.For(engineContext.CurrentController).Return(controller);
            SetupResult.For(engineContext.CurrentControllerContext).Return(controllerContext);
            SetupResult.For(engineContext.Flash).Return(flash);
            SetupResult.For(engineContext.Session).Return(session);
            SetupResult.For(engineContext.Items).Return(contextItems);

            SetupResult.For(request.Params).Return(requestParams);

            SetupResult.For(controllerContext.LayoutNames).Return(new[] { "default" });
            SetupResult.For(controllerContext.Helpers).Return(helpers);
            SetupResult.For(controllerContext.PropertyBag).Return(propertyBag);

            SetupResult.For(routingEngine.IsEmpty).Return(true);

            var urlBuilder = new DefaultUrlBuilder(server, routingEngine);

            var serviceProvider = mocks.CreateMock<IServiceProvider>();
            var viewSourceLoader = new FileAssemblyViewSourceLoader("Views");
            SetupResult.For(serviceProvider.GetService(typeof(IViewSourceLoader))).Return(viewSourceLoader);
            SetupResult.For(serviceProvider.GetService(typeof(ILoggerFactory))).Return(new NullLogFactory());
            SetupResult.For(serviceProvider.GetService(typeof(ISparkViewEngine))).Return(null);
            SetupResult.For(serviceProvider.GetService(typeof(IUrlBuilder))).Return(urlBuilder);
            SetupResult.For(serviceProvider.GetService(typeof(IViewComponentFactory))).Return(null);
            mocks.Replay(serviceProvider);

            SetupResult.For(engineContext.GetService(null)).IgnoreArguments().Do(
                new Func<Type, object>(serviceProvider.GetService));

            factory.Service(serviceProvider);


            manager = new DefaultViewEngineManager();
            manager.RegisterEngineForExtesionLookup(factory);
            manager.RegisterEngineForView(factory);
        }
开发者ID:mgagne-atman,项目名称:Projects,代码行数:60,代码来源:SparkViewFactoryTests.cs

示例6: Perform

        public bool Perform(ExecuteWhen exec, IEngineContext context, IController controller, IControllerContext controllerContext)
        {
            /*
            ArrayList admins = new ArrayList();
            admins.Add("jpino");
            admins.Add("logas");
            admins.Add("lmolina");

            if (admins.Contains (context.CurrentUser.Identity.Name.ToLower()))
                return true;
            else {
                context.Flash["TypeMsg"] = "alert alert-error";
                context.Flash["Msg"] = "Error : No eres admin";

                context.Response.RedirectToUrl ("/");
                return false;
            }
            */
            if (context.CurrentUser.IsInRole ("admin"))
                return true;
            else {
                context.Flash["TypeMsg"] = "alert alert-error";
                context.Flash["Msg"] = "Error : No eres admin";

                context.Response.RedirectToUrl ("/");
                return false;
            }
        }
开发者ID:joil,项目名称:Compras,代码行数:28,代码来源:AdminFilter.cs

示例7: Contextualize

		/// <summary>
		/// Sets the context for the controller
		/// </summary>
		/// <param name="engineContext">The engine context.</param>
		/// <param name="context">The controller context.</param>
		public virtual void Contextualize(IEngineContext engineContext, IControllerContext context)
		{
			this.context = context;
			SetEngineContext(engineContext);
			renderingSupport = new RenderingSupport(context, engineContext);
			isContextualized = true;
		}
开发者ID:ralescano,项目名称:castle,代码行数:12,代码来源:Controller.cs

示例8: CreateJSCodeGeneratorInfo

        /// <summary>
        /// Creates the JS code generator info. Temporarily on IViewEngineManager
        /// </summary>
        /// <param name="engineContext">The engine context.</param>
        /// <param name="controller">The controller.</param>
        /// <param name="controllerContext">The controller context.</param>
        /// <returns></returns>
        public JSCodeGeneratorInfo CreateJSCodeGeneratorInfo(IEngineContext engineContext, IController controller,
            IControllerContext controllerContext)
        {
            var codeGen = new JSCodeGenerator();

            return new JSCodeGeneratorInfo(codeGen, new PrototypeGenerator(codeGen), new object[0], new object[0]);
        }
开发者ID:Eilon,项目名称:spark,代码行数:14,代码来源:InjectableStubViewEngineManager.cs

示例9: OnAfterRendering

 protected override void OnAfterRendering(IEngineContext context, IController controller,
                                          IControllerContext controllerContext){
     if (writeAfterAction){
         return;
     }
     doLog(context);
 }
开发者ID:Qorpent,项目名称:comdiv.oldcore,代码行数:7,代码来源:OperationLogFilter.cs

示例10: ExecuteResult

 /// <summary>
 /// Execute the response result.
 /// </summary>
 /// <param name="context">HTTP controller context</param>
 /// <remarks>Invoked by <see cref="ControllerFactory"/> to process the response.</remarks>
 public override void ExecuteResult(IControllerContext context)
 {
     if (string.IsNullOrEmpty(_url))
     {
         string body = @"<!DOCTYPE html><html><head><META http-equiv='refresh' content='0;URL=" + _url + @"'</head><body></body></html>";
         context.HttpContext.Response.Content = new HttpStringContent(body, UnicodeEncoding.Utf8);
     }
 }
开发者ID:microcompiler,项目名称:microserver.uwp,代码行数:13,代码来源:RedirectResult.cs

示例11: Rescue

        public void Rescue(Exception exception, IController controller, IControllerContext controllerContext)
        {
            var statusCode = GetStatusCode(exception);
            PropertyBag.Add("statusCode", statusCode);
            PropertyBag.Add("message", exception.Message);

            Response.StatusCode = statusCode;
        }
开发者ID:MartinZulu,项目名称:LeTour,代码行数:8,代码来源:RescueController.cs

示例12: Bind

 public object Bind(IEngineContext context, IController controller, IControllerContext controllerContext, ParameterInfo parameterInfo)
 {
     string token = context.Request[parameterInfo.Name];
     Type type = parameterInfo.ParameterType;
     if (CanConvert(type, token))
         return Convert.ChangeType(token, type);
     return value;
 }
开发者ID:Tigraine,项目名称:ic-website,代码行数:8,代码来源:DefaultValueAttribute.cs

示例13: OnBeforeAction

        protected override bool OnBeforeAction(IEngineContext context, IController controller,
                                               IControllerContext controllerContext){
          //  ioc.get<IRequestConversationHandler>().PrepareConversationOnBegin();
            ((Controller) controller).PropertyBag["conversation"] = myapp.conversation.Current;
            ((Controller) controller).PropertyBag["conversationKey"] = myapp.conversation.Current.Code;

            return true;
        }
开发者ID:Qorpent,项目名称:comdiv.oldcore,代码行数:8,代码来源:ConversationFilter.cs

示例14: OnBeforeAction

 protected override bool OnBeforeAction(IEngineContext context, IController controller,
                                        IControllerContext controllerContext){
     var mvc = MvcContext.Create((Controller) controller);
     var logname = acl.token(mvc).Replace("/", ".").Substring(1);
     var log = logger.get(logname);
     log.info(() => myapp.usrName + "\t\tBEFORE_ACTION:\t" + acl.token(mvc));
     return true;
 }
开发者ID:Qorpent,项目名称:comdiv.oldcore,代码行数:8,代码来源:LogFilter.cs

示例15: Init

        public void Init(IControllerContext controllerContext, IEngineContext engineContext)
        {
            Invariant.ArgumentNotNull(controllerContext, "controllerContext");

            ViewContext = engineContext;

            PropertyBag = controllerContext.PropertyBag;
        }
开发者ID:mgagne-atman,项目名称:Projects,代码行数:8,代码来源:NHamlMonoRailView.cs


注:本文中的IControllerContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。