2
我剛發現an article在CodeProject上,這讓我很感興趣。所以我實現了這一個位置:WebResource.axd的給404
我有兩個項目:
- MyComponent.Web (持有的所有資源和控制)
- MyComponent.Web.Demo(只是webProject)
在MyComponent.Web我有
的AssemblyInfo.cs
[assembly: WebResource(WebResourceHelper.JQueryPath, "text/javascript")]
WebResourceHelper.cs
public static class WebResourceHelper
{
internal const string JQueryPath = "MyComponent.Web.WebResources.jQuery.jquery-1.5.1.min.js";
public static void RegisterJQuery(this Page page)
{
page.RegisterWebResource(JQueryPath);
}
public static void RegisterWebResource(this Page page, string path)
{
Contract.Requires(page != null);
Contract.Requires(!string.IsNullOrEmpty(path));
var pageType = page.GetType();
var webResourcePath = page.ClientScript.GetWebResourceUrl(pageType, path);
page.ClientScript.RegisterClientScriptResource(pageType, webResourcePath);
}
}
TextBox.cs
// namespace: MyComponent.Web.UI.WebControls
public sealed class TextBox : System.Web.UI.WebControls.TextBox
{
#region life cycle
protected override void OnInit(System.EventArgs e)
{
base.OnInit(e);
this.Page.RegisterJQuery();
}
#endregion
}
,另外我的腳本文件,生成操作設置爲Embedded Resource
在MyComponent.Web.Demo
我
Default.aspx的
<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<myComponent:TextBox runat="server" ID="textBox" />
</div>
</form>
</body>
</html>
的web.config
<system.web>
<pages>
<controls>
<add tagPrefix="myComponent" namespace="MyComponent.Web.UI.WebControls" assembly="MyComponent.Web" />
</controls>
</pages>
</system.web>
但WebResource.axd
給了我一個40 4,而Reflector向我展示了,我正確地嵌入了資源 - 所以我在這裏做錯了什麼?
編輯 您可以下載a demo here
這個問題是否類似? http://stackoverflow.com/questions/435311/asp-net-webresource-axd-call-404-error-how-to-know-which-assembly-resource-is-m – Shoban 2011-03-02 08:06:04
@Shoban:nope ... the telerik工具爲我提供了'pApp_Web_7jmvne45 | MyComponent.Web.WebResources.jQuery.jquery-1.5.1.min.js'這對我來說看起來是正確的......值得注意的是:dropDown'選擇此頁上的Web資源:'telerik工具沒有元素... – 2011-03-02 08:12:58