我正在获取用于缩小和压缩的 css 文件,这些文件适用QueryString["path"]
于我自己的 css 文件(如 main.css)。但是当我尝试访问网络资源文件时,我收到 500 错误。webresource.axd 之后的参数区分大小写,我从小写接收它QueryString["path"]
。
这就是我从中得到的QueryString["path"]
:
http://localhost/test/webresource.axd?d=-phgrn6r6zgehvbi697-bxvkl_gidnplxpdeukz5kncgr9hvnfvttpgykwyw05cda-nymtz9od_bbww3ynzxha2&t=633789305460522066
上面的链接生成错误: CryptographicException: Padding is invalid and cannot be removed。
这是正确链接的样子:
http://localhost/test/WebResource.axd?d=-pHGRn6r6ZGehvBI697-BxVKl_GIdNPlxPdEUKZ5KNcGR9hvnfVtTpgyKwYw05cDa-NymTz9OD_bBwW3ynZXhA2&t=633789305460522066
唯一的区别在于情况。CryptographicException 似乎很常见,但即使设置 machineKey 也不能解决问题。关于如何在原始案例中获得 webresource.axd 的任何提示?
编辑
要求代码:
public void ProcessRequest(HttpContext context) {
Control c = new Control();
string root = context.Request.Url.GetLeftPart(UriPartial.Authority);
string path = context.Request.QueryString["path"];
string content = string.Empty;
if (!string.IsNullOrEmpty(path)) {
if (context.Cache[path] == null) {
List<string> dependencies = new List<string>();
string[] styles = path.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
foreach (string style in styles) {
content += RetrieveStyle(root + c.ResolveUrl(style)) + Environment.NewLine;
dependencies.Add(context.Server.MapPath(style));
}
content = StripWhitespace(content);
context.Cache.Insert(path, content, new CacheDependency(dependencies.ToArray()), Cache.NoAbsoluteExpiration, new TimeSpan(DAYS_IN_CACHE, 0, 0, 0));
}
}
}
当我打电话时它在 RetriveStyle 崩溃:
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())