[英]WebResource.axd 404
I have encountered a problem loading .css file using WebResource in ASP.NET Webform project.我在 ASP.NET Webform 项目中使用 WebResource 加载 .css 文件时遇到问题。 The project refers to a sharedProject folder.该项目引用了一个 sharedProject 文件夹。 Every page in the project inherits from a common base page inside the sharedProject.项目中的每个页面都继承自 sharedProject 中的公共基页。 Now I create a CommonStyle.css inside sharedProject and try to inject it into the base page.现在我在 sharedProject 中创建一个 CommonStyle.css 并尝试将它注入到基页中。
Weird thing is that the WebResource with 404 error message has a type of "text/html".奇怪的是,带有 404 错误消息的 WebResource 的类型是“text/html”。 After I move the PageBase.cs into MyProject folder, the WebResource can then successfully load.将 PageBase.cs 移动到 MyProject 文件夹后,WebResource 可以成功加载。 I am so frustrated and confused right now.我现在非常沮丧和困惑。 Please help.请帮忙。
Directory structure is as follows:目录结构如下:
Code in PageBase.cs, OnInit function: PageBase.cs 中的代码,OnInit 函数:
protected override void OnInit(EventArgs e)
{
HyperLink hlHelpFile = new HyperLink();
ClientScriptManager cs = Page.ClientScript;
Type rsType = typeof(PageBase);
hlHelpFile.NavigateUrl = cs.GetWebResourceUrl(rsType, "Web.CommonStyle.css");
this.Page.Header.Controls.Add(hlHelpFile);
HtmlLink css = new HtmlLink();
css.Href = hlHelpFile.NavigateUrl;
css.Attributes.Add("rel","stylesheet");
css.Attributes.Add("type","text/css");
css.Attributes.Add("media","all");
this.Page.Header.Controls.Add(css);
base.OnInit(e);
}
I have also added webResourceAttribute in AssemblyInfo.cs as follows:我还在 AssemblyInfo.cs 中添加了 webResourceAttribute,如下所示:
[assembly: WebResourceAttribute("SharedProject.CommonStyle.css", "text/css")]
I've struggled so much but finally figured it out.我费了好大劲,终于想通了。 The thing is I put assembly information in the wrong place.问题是我把装配信息放在了错误的地方。 The WebResource assembly should always be put in the same project as the base page class (Shared Project). WebResource 程序集应始终与基页类(共享项目)放在同一个项目中。
I know this is a stupid mistake.我知道这是一个愚蠢的错误。 I will put this here in case someone else is struggling at the same problem.我会把它放在这里以防其他人在同样的问题上挣扎。
make sure max query string and maxurl size Big enough ;确保 max query string 和 maxurl size 足够大;
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="52428800" maxUrl="760" maxQueryString="390" />
<!--50MB-->
<verbs>
<add verb="TRACE" allowed="false" />
<add verb="OPTIONS" allowed="false" />
</verbs>
</requestFiltering>
<isapiCgiRestriction notListedIsapisAllowed="false" />
</security>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.