本文整理汇总了C#中System.Web.Routing.RequestContext类的典型用法代码示例。如果您正苦于以下问题:C# RequestContext类的具体用法?C# RequestContext怎么用?C# RequestContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RequestContext类属于System.Web.Routing命名空间,在下文中一共展示了RequestContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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;
}
示例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);
}
示例4: Initialize
protected override void Initialize(RequestContext requestContext)
{
if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
if (MembershipService == null) { MembershipService = new AccountMembershipService(); }
base.Initialize(requestContext);
}
示例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");
}
}
示例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);
}
示例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;
}
示例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));
}
示例9: SetUpRequestContext
private void SetUpRequestContext()
{
HttpTest.SetUpHttpContext();
requestContext = new RequestContext();
requestContext.HttpContext = new HttpContextWrapper(HttpContext.Current);
requestContext.RouteData = new RouteData();
}
示例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;
}
}
示例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;
}
示例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;
}
示例13: GetHttpHandler
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
if (_httpHandler == null)
_httpHandler = new ApplicationRouteHttpHandler(_url, _assembly);
return _httpHandler;
}
示例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);
}
示例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);
}