forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResourceRouteHandler.cs
More file actions
42 lines (34 loc) · 1.52 KB
/
ResourceRouteHandler.cs
File metadata and controls
42 lines (34 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Globalization;
using System.Web.Routing;
using System.Web.WebPages.Resources;
namespace System.Web.WebPages.ApplicationParts
{
internal class ResourceRouteHandler : IRouteHandler
{
private ApplicationPartRegistry _partRegistry;
public ResourceRouteHandler(ApplicationPartRegistry partRegistry)
{
_partRegistry = partRegistry;
}
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
// Get the package name and static resource path from the route
string partName = (string)requestContext.RouteData.GetRequiredString("module");
// Try to find an application module by this name
ApplicationPart module = _partRegistry[partName];
// Throw an exception if we can't find the module by name
if (module == null)
{
throw new InvalidOperationException(
String.Format(CultureInfo.CurrentCulture,
WebPageResources.ApplicationPart_ModuleCannotBeFound, partName));
}
// Get the resource path
string path = (string)requestContext.RouteData.GetRequiredString("path");
// Return the resource handler for this module and path
return new ResourceHandler(module, path);
}
}
}