[研究]IIS 10.0 GCB,"要求篩選","允許未列出的副檔名" 不勾選,實測 .axd 檔案(二)
2025-01-20
環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + SQL Server 2019 + SQL Server Management Studio (SSMS) 20.2
********************************************************************************
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="WebApplication1.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>動態生成檔案範例</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div>
<asp:Label ID="Label1" runat="server" Text="按下按鈕會生成動態 .axd 檔案"></asp:Label>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="生成動態檔案" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>
|
Default.aspx.cs
using System;
namespace WebApplication1
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
// 產生一個 WebResource 的動態 URL
// ASP.NET 會生成 WebResource.axd 來提供內嵌資源
string scriptUrl = this.Page.ClientScript.GetWebResourceUrl(typeof(Default), "WebFormDynamicFileDemo.Scripts.Sample.js");
Label1.Text = "動態生成的 .axd URL: <a href='" + scriptUrl + "' target='_blank'>" + scriptUrl + "</a>";
}
}
} |
實際測試
雖然之前的測試的案例,.axd 是不用加入 "允許副檔名" 的名單就可運作;且 ChatGPT 也說理論上是不需要加入的;
但這個範例,不加入是無法運作。
下圖,加入 .axd 後,仍無法運作,變成另一種問題。
****************************************
和 ChatGPT 談很久,總結它的觀點
「不用加入白名單的 .axd」,其實只限於 ASP.NET 內建的 HTTP Handler 處理的動態資源 WebResource.axd 和 ScriptResource.axd
非 ASP.NET WebForm 架構內建的 HTTP Handler 處理,而是自己程式中的 URL 的 .axd,還是要加入白名單
(完)
相關
[研究]IIS 10.0 GCB,"要求篩選","允許未列出的副檔名" 不勾選,ASP.NET WebForm 動態生成的檔案,副檔名都不用加入"允許副檔名" 名單嗎?
https://shaurong.blogspot.com/2026/01/iis-100-gcb-aspnet-webform.html



沒有留言:
張貼留言