You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ASP.NET WebForms无.aspx扩展名请求404问题求助

解决ASP.NET WebForms无扩展名页面请求404问题

你的问题是无扩展名的页面请求(如SearchForm?parameter=value)返回404,仅带.aspx扩展名的请求可正常处理,需通过修改web.config配置让ASP.NET支持无扩展名请求,具体方案如下:

修改后的完整web.config代码

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  https://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.8" />
    <httpRuntime targetFramework="4.8" />
    <!-- 可选:仅需特定页面支持无扩展名时,取消注释并添加对应映射 -->
    <!--
    <urlMappings enabled="true">
      <add url="~/SearchForm" mappedUrl="~/SearchForm.aspx"/>
    </urlMappings>
    -->
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" 
           path="*." 
           verb="GET,HEAD,POST,DEBUG" 
           type="System.Web.Handlers.TransferRequestHandler" 
           preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=&quot;Web&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
</configuration>

关键配置说明

  • <modules runAllManagedModulesForAllRequests="true">:强制所有请求(包括无扩展名请求)经过ASP.NET托管模块处理,确保WebForms框架能捕获请求。
  • <handlers>中的ExtensionlessUrlHandler-Integrated-4.0:专门处理无扩展名URL,将请求转发给ASP.NET处理,避免IIS直接返回404。
  • 可选<urlMappings>:若仅需特定页面支持无扩展名,取消注释该节点并添加对应映射;若要全局支持所有.aspx页面无扩展名请求,仅保留system.webServer配置即可。

配置完成后重启应用池,无扩展名的SearchForm?parameter=value请求即可正常触发重定向逻辑。

内容的提问来源于stack exchange,提问作者Wallace B. McClure

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 10:35:09