本文整理汇总了C#中HttpContextBase.RemapHandler方法的典型用法代码示例。如果您正苦于以下问题:C# HttpContextBase.RemapHandler方法的具体用法?C# HttpContextBase.RemapHandler怎么用?C# HttpContextBase.RemapHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpContextBase
的用法示例。
在下文中一共展示了HttpContextBase.RemapHandler方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoPostResolveRequestCache
internal void DoPostResolveRequestCache(HttpContextBase context) {
// Parse incoming URL (we trim off the first two chars since they're always "~/")
string requestPath = context.Request.AppRelativeCurrentExecutionFilePath.Substring(2) + context.Request.PathInfo;
// Check if this request matches a file in the app
WebPageMatch webpageRouteMatch = MatchRequest(requestPath, WebPageHttpHandler.GetRegisteredExtensions(), VirtualPathFactoryManager);
if (webpageRouteMatch != null) {
// If it matches then save some data for the WebPage's UrlData
context.Items[typeof(WebPageMatch)] = webpageRouteMatch;
string virtualPath = "~/" + webpageRouteMatch.MatchedPath;
// Verify that this path is enabled before remapping
if (!WebPagesDeployment.IsExplicitlyDisabled(virtualPath)) {
IHttpHandler handler = WebPageHttpHandler.CreateFromVirtualPath(virtualPath);
if (handler != null) {
// Remap to our handler
context.RemapHandler(handler);
}
}
}
else {
// Bug:904704 If its not a match, but to a supported extension, we want to return a 404 instead of a 403
string extension = PathUtil.GetExtension(requestPath);
foreach (string supportedExt in WebPageHttpHandler.GetRegisteredExtensions()) {
if (String.Equals("." + supportedExt, extension, StringComparison.OrdinalIgnoreCase)) {
throw new HttpException(404, null);
}
}
}
}
示例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) {
return;
}
// If a route was found, get an IHttpHandler from the route's RouteHandler
IRouteHandler routeHandler = routeData.RouteHandler;
if (routeHandler == null) {
throw new InvalidOperationException(
String.Format(
CultureInfo.CurrentCulture,
SR.GetString(SR.UrlRoutingModule_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;
IHttpHandler httpHandler = routeHandler.GetHttpHandler(requestContext);
if (httpHandler == null) {
throw new InvalidOperationException(
String.Format(
CultureInfo.CurrentUICulture,
SR.GetString(SR.UrlRoutingModule_NoHttpHandler),
routeHandler.GetType()));
}
if (httpHandler is UrlAuthFailureHandler) {
if (FormsAuthenticationModule.FormsAuthRequired) {
UrlAuthorizationModule.ReportUrlAuthorizationFailure(HttpContext.Current, this);
return;
}
else {
throw new HttpException(401, SR.GetString(SR.Assess_Denied_Description3));
}
}
// Remap IIS7 to our handler
context.RemapHandler(httpHandler);
}