我已经在我的 asp.net c# web 应用程序中创建了处理程序来处理 .html 页面。
我也使用 url 重写概念。
当任何 html 请求到达服务器/网站时,处理程序工作正常。
编码细节如下:
web.config 处理程序代码:
<add verb="*" path="*.html," validate="false" type="MyProject.ContentHandler,MyProject" />
ContentHandler.cs代码:
public void ProcessRequest(HttpContext context)
{
string strMapPage = string.Empty;
if (context.Request.Url.ToString().Contains("category"))
{
strMapPage = "/Links.aspx?ID=" + ProducID;
}
else
{
strMapPage = context.Request.Url.ToString();
}
context.Server.Transfer(strMapPage);
}
此方法适用于任何 .html 请求,例如此页面 http://localhost:9111/user-category-1.html
但是当我尝试打开像“/JS/TinyMCE/imagemanager/index.html”这样的页面时
它抛出错误“执行/JS/TinyMCE/imagemanager/index.html 的子请求时出错”
如何解决这个问题?
最佳答案
来自微软:
Microsoft Internet Information Services (IIS) 根据请求文件的扩展名将 Server.Transfer 或 Server.Execute 请求分派(dispatch)到适当的 Internet 服务器应用程序编程接口(interface) (ISAPI) 扩展名。例如,对 .aspx 页面的请求被分派(dispatch)到 Aspnet_isapi.dll ISAPI 扩展。
请求被分派(dispatch)到适当的 ISAPI 扩展后,ISAPI 扩展不能调用另一个 ISAPI 扩展。您收到错误消息“执行 PageName.asp 的子请求时出错”,因为处理对 ASP.NET 页面的请求的 Aspnet_isapi.dll 文件无法将请求转发到处理对 ASP 页面的请求的 Asp.dll 文件。
你的管理员正在制造问题,
试试这个: 这是由另一个应用程序添加的自定义 HTTP 处理程序引起的,该应用程序很可能在您的网站的根目录中运行。要解决该问题,请修改 web.config 文件。添加后:
<httpHandlers>
<clear />
<add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory" />
</httpHandlers>
关于c# - 使用 Handler 执行 server.transfer 的子请求时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9629122/