我使用ASP.Net和表單身份驗證。當用戶被定向到登錄頁面,我得到一個JavaScript錯誤:ASP.Net - 如何在使用表單身份驗證時允許未經身份驗證的用戶查看導入的腳本文件?
Message: Syntax error Line: 3 Char: 1 Code: 0 URI: http://localhost:49791/login.aspx?ReturnUrl=%2fWebImageButton.js
這是因爲我使用一個單獨的網絡控制項目的控制,增加了使用ScriptReference頁面自定義圖像按鈕:
public class WebImageButton : LinkButton, IScriptControl, IButtonControl
{
protected override void OnPreRender(EventArgs e)
{
// Link the script up with the script manager
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
if (scriptManager != null)
{
scriptManager.RegisterScriptControl(this);
scriptManager.Scripts.Add(new ScriptReference("<snip>.WebImageButton.js", "<snip>"));
}
base.OnPreRender(e);
}
}
如果我添加下面的規則到我的web.config,則該文件已成功導入:
<location path="WebImageButton.js">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
這是不是很好,因爲我有一些自定義的控件,做T他同樣的事情,我並不特別喜歡單獨驗證他們的每個js文件。
是否有沒有辦法可以聲明所有導入的腳本引用都應該被允許?我試圖在允許的情況下授權WebResource.axd文件,但是頁面本身(渲染時)會物理引用WebImageButton.js文件。
理想的情況是類似以下內容:
<location path="My.WebControlLibraryProject.Controls">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
有什麼辦法來實現這一目標,而不列出每個文件?
編輯:要清楚,這些腳本文件在另一個項目中,不在我的實際Web項目。我知道如何聲明目錄路徑的位置路徑以包含大量文件,但我無法弄清楚如何驗證來自嵌入式資源的自動腳本引用。
那麼,你不能把最特殊的符號放到位置路徑。 – GenericTypeTea 2009-11-18 16:38:42