本文整理汇总了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));
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
}
示例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;
}
示例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]);
}
示例9: OnAfterRendering
protected override void OnAfterRendering(IEngineContext context, IController controller,
IControllerContext controllerContext){
if (writeAfterAction){
return;
}
doLog(context);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例15: Init
public void Init(IControllerContext controllerContext, IEngineContext engineContext)
{
Invariant.ArgumentNotNull(controllerContext, "controllerContext");
ViewContext = engineContext;
PropertyBag = controllerContext.PropertyBag;
}