本文整理汇总了C#中System.Web.HttpContextBase.RemapHandler方法的典型用法代码示例。如果您正苦于以下问题:C# HttpContextBase.RemapHandler方法的具体用法?C# HttpContextBase.RemapHandler怎么用?C# HttpContextBase.RemapHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpContextBase
的用法示例。
在下文中一共展示了HttpContextBase.RemapHandler方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PostResolveRequestCache
public virtual void PostResolveRequestCache(HttpContextBase context)
{
RouteData routeData = this.RouteCollection.GetRouteData(context);
if (routeData != null)
{
IRouteHandler routeHandler = routeData.RouteHandler;
if (routeHandler == null)
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, System.Web.SR.GetString("UrlRoutingModule_NoRouteHandler"), new object[0]));
}
if (!(routeHandler is StopRoutingHandler))
{
RequestContext requestContext = new RequestContext(context, routeData);
context.Request.RequestContext = requestContext;
IHttpHandler httpHandler = routeHandler.GetHttpHandler(requestContext);
if (httpHandler == null)
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, System.Web.SR.GetString("UrlRoutingModule_NoHttpHandler"), new object[] { routeHandler.GetType() }));
}
if (httpHandler is UrlAuthFailureHandler)
{
if (!FormsAuthenticationModule.FormsAuthRequired)
{
throw new HttpException(0x191, System.Web.SR.GetString("Assess_Denied_Description3"));
}
UrlAuthorizationModule.ReportUrlAuthorizationFailure(HttpContext.Current, this);
}
else
{
context.RemapHandler(httpHandler);
}
}
}
}
示例2: PostResolveRequestCache
public virtual void PostResolveRequestCache(HttpContextBase context)
{
// Match the incoming URL against the route table
RouteData routeData = RouteCollection.GetRouteData(context);
// Do nothing if no route found
if (routeData == null)
{
SegmentLang.Instance.ResolveRequest(context, routeData);
return;
}
// If a route was found, get an IHttpHandler from the route's RouteHandler
IRouteHandler routeHandler = routeData.RouteHandler;
if (routeHandler == null)
{
SegmentLang.Instance.ResolveRequest(context, routeData);
throw new InvalidOperationException(
String.Format(
CultureInfo.CurrentCulture, "NoRouteHandler"));
}
// This is a special IRouteHandler that tells the routing module to stop processing
// routes and to let the fallback handler handle the request.
if (routeHandler is StopRoutingHandler)
{
return;
}
RequestContext requestContext = new RequestContext(context, routeData);
// Dev10 766875 Adding RouteData to HttpContext
context.Request.RequestContext = requestContext;
// AiLib
SegmentLang.Instance.ResolveRequest(context, routeData);
IHttpHandler httpHandler = routeHandler.GetHttpHandler(requestContext);
if (httpHandler == null)
{
throw new InvalidOperationException(
String.Format(
CultureInfo.CurrentUICulture,
"NoHttpHandler {0}",
routeHandler.GetType())
);
}
var fullName = httpHandler.GetType().FullName;
// (httpHandler is UrlAuthFailureHandler)
if (fullName.Contains("UrlAuthFailure")) // System.Web.Routing.UrlAuthFailureHandler
{
//if (FormsAuthenticationModule.FormsAuthRequired)
//{
// UrlAuthorizationModule.ReportUrlAuthorizationFailure(HttpContext.Current, this);
// return;
throw new HttpException(401, "Access denied"); // _Description3
}
// Remap IIS7 to our handler:
// class System.Web.HttpContextBase
// virtual void RemapHandler(IHttpHandler handler)
context.RemapHandler(httpHandler);
}
示例3: ProcessRequest
/// <summary>
/// Assigns the request to the http context and proceeds to process the request. If everything is successful, invoke the callback.
/// </summary>
/// <param name="httpContext"></param>
/// <param name="umbracoContext"></param>
/// <param name="onSuccess"></param>
internal void ProcessRequest(HttpContextBase httpContext, UmbracoContext umbracoContext, Action<PublishedContentRequest> onSuccess)
{
if (umbracoContext == null)
throw new NullReferenceException("The UmbracoContext.Current is null, ProcessRequest cannot proceed unless there is a current UmbracoContext");
if (umbracoContext.RoutingContext == null)
throw new NullReferenceException("The UmbracoContext.RoutingContext has not been assigned, ProcessRequest cannot proceed unless there is a RoutingContext assigned to the UmbracoContext");
//assign back since this is a front-end request
umbracoContext.PublishedContentRequest = this;
// note - at that point the original legacy module did something do handle IIS custom 404 errors
// ie pages looking like /anything.aspx?404;/path/to/document - I guess the reason was to support
// "directory urls" without having to do wildcard mapping to ASP.NET on old IIS. This is a pain
// to maintain and probably not used anymore - removed as of 06/2012. @zpqrtbnk.
//
// to trigger Umbraco's not-found, one should configure IIS and/or ASP.NET custom 404 errors
// so that they point to a non-existing page eg /redirect-404.aspx
// TODO: SD: We need more information on this for when we release 4.10.0 as I'm not sure what this means.
//find domain
_builder.LookupDomain();
// redirect if it has been flagged
if (this.IsRedirect)
httpContext.Response.Redirect(this.RedirectUrl, true);
//set the culture on the thread - once, so it's set when running document lookups
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = this.Culture;
//find the document, found will be true if the doc request has found BOTH a node and a template
// though currently we don't use this value.
var found = _builder.LookupDocument();
//set the culture on the thread -- again, 'cos it might have changed due to a wildcard domain
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = this.Culture;
//this could be called in the LookupDocument method, but I've just put it here for clarity.
_builder.DetermineRenderingEngine();
//TODO: here we should launch an event so that people can modify the doc request to do whatever they want.
// redirect if it has been flagged
if (this.IsRedirect)
httpContext.Response.Redirect(this.RedirectUrl, true);
// handle 404
if (this.Is404)
{
httpContext.Response.StatusCode = 404;
httpContext.Response.TrySkipIisCustomErrors = Umbraco.Core.Configuration.UmbracoSettings.TrySkipIisCustomErrors;
if (!this.HasNode)
{
httpContext.RemapHandler(new PublishedContentNotFoundHandler());
return;
}
// else we have a document to render
// not having a template is ok here, MVC will take care of it
}
// just be safe - should never ever happen
if (!this.HasNode)
throw new Exception("No document to render.");
// trigger PublishedContentRequest.Rendering event?
// with complete access to the content request?
// render even though we might have no template
// to give MVC a chance to hijack routes
// pass off to our handlers (mvc or webforms)
// assign the legacy page back to the docrequest
// handlers like default.aspx will want it and most macros currently need it
this.UmbracoPage = new page(this);
// these two are used by many legacy objects
httpContext.Items["pageID"] = this.DocumentId;
httpContext.Items["pageElements"] = this.UmbracoPage.Elements;
if (onSuccess != null)
onSuccess(this);
}
示例4: PostResolveRequestCache
public virtual void PostResolveRequestCache (HttpContextBase context)
{
if (context == null)
throw new ArgumentNullException ("context");
var rd = RouteCollection.GetRouteData (context);
if (rd == null)
return; // do nothing
if (rd.RouteHandler == null)
throw new InvalidOperationException ("No IRouteHandler is assigned to the selected route");
if (rd.RouteHandler is StopRoutingHandler)
return; //stop further processing
var rc = new RequestContext (context, rd);
IHttpHandler http = rd.RouteHandler.GetHttpHandler (rc);
if (http == null)
throw new InvalidOperationException ("The mapped IRouteHandler did not return an IHttpHandler");
context.Request.RequestContext = rc;
context.RemapHandler (http);
}
示例5: PostResolveRequestCache
public virtual void PostResolveRequestCache (HttpContextBase context)
{
if (context == null)
throw new ArgumentNullException ("context");
var rd = RouteCollection.GetRouteData (context);
if (rd == null)
return; // do nothing
if (rd.RouteHandler == null)
throw new InvalidOperationException ("No IRouteHandler is assigned to the selected route");
if (rd.RouteHandler is StopRoutingHandler)
return; //stop further processing
var rc = new RequestContext (context, rd);
IHttpHandler http = rd.RouteHandler.GetHttpHandler (rc);
if (http == null)
throw new InvalidOperationException ("The mapped IRouteHandler did not return an IHttpHandler");
#if NET_4_0
context.Request.RequestContext = rc;
context.RemapHandler (http);
#else
// note: It does not resolve paths using GetVirtualPath():
//var vpd = RouteCollection.GetVirtualPath (rc, rd.Values);
//context.RewritePath (vpd.VirtualPath);
context.Items [original_path_key] = context.Request.Path;
// default handler (forbidden in MVC/DynamicData projects)
context.RewritePath ("~/UrlRouting.axd");
context.Items [module_identity_key] = http;
#endif
}
示例6: ProcessRequest
/// <summary>
/// Processses the Umbraco Request
/// </summary>
/// <param name="httpContext"></param>
void ProcessRequest(HttpContextBase httpContext)
{
// do not process if client-side request
if (IsClientSideRequest(httpContext.Request.Url))
return;
if (UmbracoContext.Current == null)
throw new NullReferenceException("The UmbracoContext.Current is null, ProcessRequest cannot proceed unless there is a current UmbracoContext");
if (UmbracoContext.Current.RoutingContext == null)
throw new NullReferenceException("The UmbracoContext.RoutingContext has not been assigned, ProcessRequest cannot proceed unless there is a RoutingContext assigned to the UmbracoContext");
var umbracoContext = UmbracoContext.Current;
// do not process but remap to handler if it is a base rest request
if (BaseRest.BaseRestHandler.IsBaseRestRequest(umbracoContext.OriginalRequestUrl))
{
httpContext.RemapHandler(new BaseRest.BaseRestHandler());
return;
}
// do not process if this request is not a front-end routable page
if (!EnsureUmbracoRoutablePage(umbracoContext, httpContext))
return;
// ok, process
var uri = umbracoContext.OriginalRequestUrl;
// legacy - no idea what this is but does something with the query strings
LegacyCleanUmbPageFromQueryString(ref uri);
// instanciate a request a process
// important to use CleanedUmbracoUrl - lowercase path-only version of the current url
var docreq = new PublishedContentRequest(umbracoContext.CleanedUmbracoUrl, umbracoContext.RoutingContext);
docreq.ProcessRequest(httpContext, umbracoContext,
docreq2 => RewriteToUmbracoHandler(HttpContext.Current, uri.Query, docreq2.RenderingEngine));
}
示例7: ProcessRequest
/// <summary>
/// Processses the Umbraco Request
/// </summary>
/// <param name="httpContext"></param>
void ProcessRequest(HttpContextBase httpContext)
{
// do not process if client-side request
if (httpContext.Request.Url.IsClientSideRequest())
return;
if (UmbracoContext.Current == null)
throw new InvalidOperationException("The UmbracoContext.Current is null, ProcessRequest cannot proceed unless there is a current UmbracoContext");
if (UmbracoContext.Current.RoutingContext == null)
throw new InvalidOperationException("The UmbracoContext.RoutingContext has not been assigned, ProcessRequest cannot proceed unless there is a RoutingContext assigned to the UmbracoContext");
var umbracoContext = UmbracoContext.Current;
// do not process but remap to handler if it is a base rest request
if (BaseRest.BaseRestHandler.IsBaseRestRequest(umbracoContext.OriginalRequestUrl))
{
httpContext.RemapHandler(new BaseRest.BaseRestHandler());
return;
}
// do not process if this request is not a front-end routable page
var isRoutableAttempt = EnsureUmbracoRoutablePage(umbracoContext, httpContext);
//raise event here
OnRouteAttempt(new RoutableAttemptEventArgs(isRoutableAttempt.Result, umbracoContext, httpContext));
if (!isRoutableAttempt.Success)
{
return;
}
httpContext.Trace.Write("UmbracoModule", "Umbraco request confirmed");
// ok, process
// note: requestModule.UmbracoRewrite also did some stripping of &umbPage
// from the querystring... that was in v3.x to fix some issues with pre-forms
// auth. Paul Sterling confirmed in jan. 2013 that we can get rid of it.
// instanciate, prepare and process the published content request
// important to use CleanedUmbracoUrl - lowercase path-only version of the current url
var pcr = new PublishedContentRequest(umbracoContext.CleanedUmbracoUrl, umbracoContext.RoutingContext);
umbracoContext.PublishedContentRequest = pcr;
pcr.Prepare();
// HandleHttpResponseStatus returns a value indicating that the request should
// not be processed any further, eg because it has been redirect. then, exit.
if (HandleHttpResponseStatus(httpContext, pcr))
return;
if (!pcr.HasPublishedContent)
httpContext.RemapHandler(new PublishedContentNotFoundHandler());
else
RewriteToUmbracoHandler(httpContext, pcr);
}