本文整理汇总了C#中System.Web.Routing.RequestContext类的典型用法代码示例。如果您正苦于以下问题:C# RequestContext类的具体用法?C# RequestContext怎么用?C# RequestContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RequestContext类属于System.Web.Routing命名空间,在下文中一共展示了RequestContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetControllerInstance
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
if (controllerType != null && _container.Kernel.HasComponent(controllerType))
return (IController)_container.Resolve(controllerType);
return base.GetControllerInstance(requestContext, controllerType);
}
开发者ID:devworker55,项目名称:SourceLab,代码行数:7,代码来源:WindsorControllerFactory.cs
示例2: SendWelcome
public EmailSendAttempt SendWelcome(RequestContext request, User u)
{
var template = LoadTemplate(
"template-user-welcome",
request.HttpContext.Server.MapPath("~/Messages/UserWelcome.template")
);
var url = new UrlHelper(request).Action(MVC.Public.Login.Index());
var e = Builder.Transform(
template,
new TemplateData
{
{"login", u.Login},
{"program", Application.ProgramName},
{"url", url.ToAbsoluteUrl(request.HttpContext.Request).ToString() },
},
request.HttpContext.Request
);
e.Recipient = new EmailAddress { Address = u.Email, Name = u.DisplayName };
var attempt = Sender.Send(e);
if (attempt.Success)
{
u.LastWeclomeEmailSent = DateTime.UtcNow;
UserRepository.Save(u);
}
return attempt;
}
开发者ID:nicknystrom,项目名称:AscendRewards,代码行数:27,代码来源:UserMessaging.cs
示例3: GetControllerInstance
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
if (controllerType == null)
throw new HttpException(404, string.Format("The controller for path '{0}' could not be found.", requestContext.HttpContext.Request.Path));
return (IController)kernel.Resolve(controllerType);
}
开发者ID:admgalloway,项目名称:adm.godo,代码行数:7,代码来源:WindsorControllerFactory.cs
示例4: Initialize
protected override void Initialize(RequestContext requestContext)
{
if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
if (MembershipService == null) { MembershipService = new AccountMembershipService(); }
base.Initialize(requestContext);
}
开发者ID:cmcginn,项目名称:AIM,代码行数:7,代码来源:AccountController.cs
示例5: Execute
public void Execute(RequestContext requestContext)
{
var urlType = requestContext.UrlStrongTypeFromRoute();
using (log4net.NDC.Push(urlType.FullName))
{
var steps = StepsFor(requestContext, urlType);
var stepContext = new StepContext(requestContext, urlType);
if (!steps.Any())
{
HandleNoSteps(stepContext);
return;
}
var lastContinuation = Continuation.Continue;
foreach (var step in steps)
{
_log.Info("Step: " + step);
lastContinuation = _stepInvoker.Invoke(step, stepContext);
if (lastContinuation != Continuation.Continue)
{
break;
}
}
if (lastContinuation == Continuation.Continue)
{
HandleNoEndingStep(stepContext);
return;
}
_log.Info("Completed");
}
}
开发者ID:aaronjensen,项目名称:splits,代码行数:34,代码来源:SplitsController.cs
示例6: GetControllerInstance
/// <summary>
/// Gets controller instance
/// </summary>
/// <param name="requestContext">request context </param>
/// <param name="controllerType">controloler that has been requested</param>
/// <returns>IController</returns>
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
if (controllerType == null)
return base.GetControllerInstance(requestContext, controllerType);
return DiContainer.Resolve<IController>(controllerType.FullName);
}
开发者ID:AndyCC,项目名称:Jumbleblocks-website,代码行数:13,代码来源:WindsorControllerFactory.cs
示例7: GetVirtualPath
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
VirtualPathData path = base.GetVirtualPath(requestContext, values);
if (path != null)
{
string virtualPath = path.VirtualPath;
var lastIndexOf = virtualPath.LastIndexOf("?");
if (lastIndexOf != 0)
{
if (lastIndexOf > 0)
{
string leftPart = virtualPath.Substring(0, lastIndexOf).ToLowerInvariant();
string queryPart = virtualPath.Substring(lastIndexOf);
path.VirtualPath = leftPart + queryPart;
}
else
{
path.VirtualPath = path.VirtualPath.ToLowerInvariant();
}
}
}
return path;
}
开发者ID:yimogit,项目名称:YimoFramework,代码行数:26,代码来源:LowercaseRoute.cs
示例8: GetRedirectHandlerWithDefaults
private static IHttpHandler GetRedirectHandlerWithDefaults(RequestContext requestContext)
{
var routeValues = requestContext.RouteData.Values;
routeValues["culture"] = LocaleHelper.DefaultCulture;
SetLocaleCookie(requestContext, LocaleHelper.DefaultCulture);
return new RedirectHandler(new UrlHelper(requestContext).RouteUrl(routeValues));
}
开发者ID:arzion,项目名称:TemplateProject,代码行数:7,代码来源:LocalizedRouteHandler.cs
示例9: SetUpRequestContext
private void SetUpRequestContext()
{
HttpTest.SetUpHttpContext();
requestContext = new RequestContext();
requestContext.HttpContext = new HttpContextWrapper(HttpContext.Current);
requestContext.RouteData = new RouteData();
}
开发者ID:jarrettmeyer,项目名称:curiosity-common-mvc,代码行数:7,代码来源:LowercaseRouteTests.cs
示例10: ControllerContextFactory
private ControllerContext ControllerContextFactory(RequestContext requestContext, string controllerName, string areaName)
{
try
{
IController controller = ControllerBuilder.Current.GetControllerFactory().CreateController(requestContext, controllerName);
if (controller == null)
{
return null;
}
if (areaName.HasValue() && !controller.GetType().FullName.Contains("Areas"))
{
IList<Type> controllerTypes = controllerTypeCache.GetControllerTypes(controllerName) ?? new List<Type>();
Type controllerType = GetControllerByArea(controllerTypes, areaName);
controller = (IController)Activator.CreateInstance(controllerType);
}
return new ControllerContext(requestContext, controller as ControllerBase);
}
catch (Exception)
{
return null;
}
}
开发者ID:wanaxe,项目名称:Study,代码行数:26,代码来源:ControllerContextCache.cs
示例11: AddNodeRecursive
private SiteMapNode AddNodeRecursive(XmlNode xmlNode, SiteMapNode parent, RequestContext context)
{
var routeValues = (from XmlNode attrib in xmlNode.Attributes
where !reservedNames.Contains(attrib.Name.ToLower())
select new { attrib.Name, attrib.Value }).ToDictionary(x => x.Name, x => (object)x.Value);
RouteValueDictionary routeDict = new RouteValueDictionary(routeValues);
VirtualPathData virtualPathData = RouteTable.Routes.GetVirtualPath(context, routeDict);
if (virtualPathData == null)
{
string message = "RoutingSiteMapProvider is unable to locate Route for " +
"Controller: '" + routeDict["controller"] + "', Action: '" + routeDict["action"] + "'. " +
"Make sure a route has been defined for this SiteMap Node.";
throw new InvalidOperationException(message);
}
string url = virtualPathData.VirtualPath;
string title = xmlNode.Attributes["title"].Value;
SiteMapNode node = new SiteMapNode(this, Guid.NewGuid().ToString(), url, title);
base.AddNode(node, parent);
foreach (XmlNode childNode in xmlNode.ChildNodes)
{
AddNodeRecursive(childNode, node, context);
}
return node;
}
开发者ID:Sironfoot,项目名称:T3ME,代码行数:31,代码来源:RoutingSiteMapProvider.cs
示例12: GetHttpHandler
/// <summary>
/// Provides the object that processes the request.
/// </summary>
/// <param name="requestContext">An object that encapsulates information about the request.</param>
/// <returns>An object that processes the request.</returns>
public override IHttpHandler GetHttpHandler(RequestContext requestContext)
{
var handler = base.GetHttpHandler(requestContext);
new PageInitializer().Initialize(handler);
return handler;
}
开发者ID:RifasRazick,项目名称:feather,代码行数:12,代码来源:MvcVersioningRouteHandler.cs
示例13: GetHttpHandler
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
if (_httpHandler == null)
_httpHandler = new ApplicationRouteHttpHandler(_url, _assembly);
return _httpHandler;
}
开发者ID:JoB70,项目名称:Bifrost,代码行数:7,代码来源:ApplicationRouteHandler.cs
示例14: GetHttpHandler
protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
{
var culture = requestContext.RouteData.Values["culture"] as string;
if (culture == null)
{
throw new InvalidOperationException("URL parameter 'culture' is required");
}
try
{
var ci = new CultureInfo(culture);
Thread.CurrentThread.CurrentUICulture = ci;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name);
// If route's culture is different from cookie's, update cookie
var cookieLocale = requestContext.HttpContext.Request.Cookies["locale"];
if (cookieLocale == null || cookieLocale.Value != culture)
{
// Save route's culture to cookie
requestContext.HttpContext.Response.Cookies.Add(new HttpCookie("locale", culture));
}
}
catch (CultureNotFoundException)
{
throw new InvalidOperationException("URL parameter 'culture' is invalid");
}
return base.GetHttpHandler(requestContext);
}
开发者ID:johnsmith9264,项目名称:Mvc4Application1,代码行数:29,代码来源:MultiCultureMvcRouteHandler.cs
示例15: GetControllerTypeInternal
/// <summary>
/// Retrieves the controller type for the specified name and request context.
/// </summary>
///
/// <returns>
/// The controller type.
/// </returns>
/// <param name="requestContext">The context of the HTTP request, which includes the HTTP context and route data.</param>
/// <param name="controllerName">The name of the controller.</param>
internal Type GetControllerTypeInternal(RequestContext requestContext, string controllerName)
{
var factory = _slaveFactories.Factories.FirstOrDefault(x => x.CanHandle(requestContext));
if (factory != null)
{
//check to see if the factory is of type UmbracoControllerFactory which exposes the GetControllerType method so we don't have to create
// an instance of the controller to figure out what it is. This is a work around for not having a breaking change for:
// http://issues.umbraco.org/issue/U4-1726
var umbFactory = factory as UmbracoControllerFactory;
if (umbFactory != null)
{
return umbFactory.GetControllerType(requestContext, controllerName);
}
//we have no choice but to instantiate the controller
var instance = factory.CreateController(requestContext, controllerName);
if (instance != null)
{
return instance.GetType();
}
return null;
}
return base.GetControllerType(requestContext, controllerName);
}
开发者ID:phaniarveti,项目名称:Experiments,代码行数:34,代码来源:MasterControllerFactory.cs
示例16: Initialize
protected override void Initialize(RequestContext requestContext)
{
string cultureName = null;
var request = requestContext.HttpContext.Request;
// Attempt to read the culture cookie from Request
var cultureCookie = request.Cookies["_culture"];
if (cultureCookie != null)
cultureName = cultureCookie.Value;
else if (request.UserLanguages != null)
cultureName = request.UserLanguages[0];
if (Localization != null)
{
// Validate culture name
cultureName = Localization.GetImplementedCulture(cultureName); // This is safe
}
if (!string.IsNullOrWhiteSpace(cultureName))
{
Thread.CurrentThread.CurrentCulture = new CultureInfo(cultureName);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(cultureName);
}
base.Initialize(requestContext);
}
开发者ID:DenisVuyka,项目名称:Masonry,代码行数:26,代码来源:MasonryControllerBase.cs
示例17: GetControllerInstance
protected override IController GetControllerInstance(RequestContext context, Type controllerType) {
if (controllerType == null) {
throw new HttpException(404, string.Format("The controller for path '{0}' could not be found or it does not implement IController.", context.HttpContext.Request.Path));
}
return (IController) container.GetService(controllerType);
}
开发者ID:Jo1nes,项目名称:SolrNet,代码行数:7,代码来源:ServiceProviderControllerFactory.cs
示例18: GetControllerInstance
/// <summary>Retrieves the controller instance for the specified request context and controller type.</summary>
///
/// <param name="requestContext">The context of the HTTP request, which includes the HTTP context and route data.</param>
/// <param name="controllerType">The type of the controller.</param>
///
/// <returns>The controller instance.</returns>
protected override IController GetControllerInstance(
RequestContext requestContext, Type controllerType)
{
try
{
if (controllerType == null)
return base.GetControllerInstance(requestContext, null);
var controller = funqBuilder.CreateInstance(controllerType) as IController;
return controller ?? base.GetControllerInstance(requestContext, controllerType);
}
catch (HttpException ex)
{
if (ex.GetHttpCode() == 404)
{
try
{
if (NServiceKitController.CatchAllController != null)
{
return NServiceKitController.CatchAllController(requestContext);
}
}
catch { } //ignore not found CatchAllController
}
throw;
}
}
开发者ID:Qasemt,项目名称:NServiceKit,代码行数:34,代码来源:FunqControllerFactory.cs
示例19: TryMatchUrl
/// <inheritdoc />
protected override bool TryMatchUrl(string[] urlParams, RequestContext requestContext)
{
var selfRouting = this.Controller as IRouteMapper;
if (urlParams != null && selfRouting != null && selfRouting.TryMapRouteParameters(urlParams, requestContext))
{
RouteHelper.SetUrlParametersResolved(true);
return true;
}
var controllerName = requestContext.RouteData.Values[FeatherActionInvoker.ControllerNameKey] as string;
string actionName = null;
if (requestContext.RouteData.Values.ContainsKey("action"))
{
actionName = requestContext.RouteData.Values["action"] as string;
requestContext.RouteData.Values.Remove("action");
}
try
{
requestContext.RouteData.Values.Remove(FeatherActionInvoker.ControllerNameKey);
MvcRequestContextBuilder.SetRouteParameters(urlParams, requestContext, this.Controller as Controller, controllerName);
}
finally
{
if (actionName != null)
{
requestContext.RouteData.Values["action"] = actionName;
}
}
return true;
}
开发者ID:RJCuthbertson,项目名称:feather,代码行数:33,代码来源:DefaultUrlParamsMapper.cs
示例20: UsesSpecifiedBinder
public void UsesSpecifiedBinder()
{
var controller = typeof(FromRouteAttr.SpecifiedBinderController);
routes.Clear();
routes.MapCodeRoutes(controller);
var httpContextMock = new Mock<HttpContextBase>();
httpContextMock.Setup(c => c.Request.AppRelativeCurrentExecutionFilePath).Returns("~/Foo/yes");
var httpResponseMock = new Mock<HttpResponseBase>();
httpContextMock.Setup(c => c.Response).Returns(httpResponseMock.Object);
var routeData = routes.GetRouteData(httpContextMock.Object);
var controllerInstance = (ControllerBase)Activator.CreateInstance(controller);
controllerInstance.ValidateRequest = false;
var requestContext = new RequestContext(httpContextMock.Object, routeData);
var controllerContext = new ControllerContext(requestContext, controllerInstance);
controllerInstance.ValueProvider = new ValueProviderCollection(new IValueProvider[] { new RouteDataValueProvider(controllerContext) });
((IController)controllerInstance).Execute(requestContext);
httpResponseMock.Verify(c => c.Write(It.Is<string>(s => s == "True")), Times.AtLeastOnce());
}
开发者ID:brettveenstra,项目名称:MvcCodeRouting,代码行数:27,代码来源:FromRouteAttributeBehavior.cs
注:本文中的System.Web.Routing.RequestContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论