Repository navigation
Expand file tree
/
Copy pathPageUtils.cs
More file actions
83 lines (74 loc) · 2.87 KB
/
Copy pathPageUtils.cs
File metadata and controls
83 lines (74 loc) · 2.87 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// 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.Collections.Generic;
using System.Text;
namespace System.Web.WebPages.Administration.PackageManager
{
internal static class PageUtils
{
private const string WebPagesPreferredTag = " aspnetwebpages ";
internal static string GetPackagesHome()
{
return SiteAdmin.GetVirtualPath("~/packages");
}
internal static string GetPageVirtualPath(string page)
{
return SiteAdmin.GetVirtualPath("~/packages/" + page);
}
internal static WebPackageSource GetPackageSource(string name)
{
if (String.IsNullOrEmpty(name))
{
return PackageManagerModule.ActiveSource;
}
// If no source is found for the specified name, default to the ActiveSource
return PackageManagerModule.GetSource(name) ?? PackageManagerModule.ActiveSource;
}
internal static string GetFilterValue(HttpRequestBase request, string cookieName, string key)
{
var value = request.QueryString[key];
if (String.IsNullOrEmpty(value))
{
var cookie = request.Cookies[cookieName];
if (cookie != null)
{
value = cookie[key];
}
}
return value;
}
internal static void PersistFilter(HttpResponseBase response, string cookieName, IDictionary<string, string> filterItems)
{
var cookie = response.Cookies[cookieName];
if (cookie == null)
{
cookie = new HttpCookie(cookieName);
response.Cookies.Add(cookie);
}
foreach (var item in filterItems)
{
cookie[item.Key] = item.Value;
}
}
internal static bool IsValidLicenseUrl(Uri licenseUri)
{
return Uri.UriSchemeHttp.Equals(licenseUri.Scheme, StringComparison.OrdinalIgnoreCase) ||
Uri.UriSchemeHttps.Equals(licenseUri.Scheme, StringComparison.OrdinalIgnoreCase);
}
/// <summary>
/// Constructs a query string from an IDictionary
/// </summary>
internal static string BuildQueryString(IDictionary<string, string> parameters)
{
StringBuilder stringBuilder = new StringBuilder();
foreach (var param in parameters)
{
stringBuilder.Append(stringBuilder.Length == 0 ? '?' : '&')
.Append(HttpUtility.UrlEncode(param.Key))
.Append('=')
.Append(HttpUtility.UrlEncode(param.Value));
}
return stringBuilder.ToString();
}
}
}