将框架从 2.0 升级到 4.0 后,URL 重写显示 404 错误

本文关键字:重写 URL 显示 错误 框架 | 更新日期: 2023-09-27 17:55:12

我刚刚将我的网站的框架从 2.0 更改为 4.0。我收到错误HTTP错误404.0 - 每当我尝试打开URL重写网页时都找不到。

它在框架 2.0 时代运行良好,现在不知道出了什么问题。我谷歌了很多东西,但没有得到任何适当的解决方案。

请帮助我解决问题。

我的代码如下:

http://www.theprojectjugaad.com/PlacementAssistance.html -> Not Working
http://www.theprojectjugaad.com/PlacementAssistance.aspx -> Working

Global.asax :

    void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes();
    }
    void Application_BeginRequest(object sender, EventArgs ex)
    {
        if (!Request.Url.Host.Equals("localhost")
            && !Request.Url.Host.ToString().Contains("www.theprojectjugaad.com")
            && Request.Url.Host.ToString().Contains("theprojectjugaad.com"))
        {
            string Result = string.Concat(
            "http://",
            Request.Url.Authority.Replace("theprojectjugaad.com", "www.theprojectjugaad.com"),
            HttpContext.Current.Response.ApplyAppPathModifier(Request.Path),
            Request.Url.Query);
            HttpContext.Current.Response.Redirect(Result, true);
        }
    }
    private static void RegisterRoutes()
    {
        System.Web.Routing.RouteTable.Routes.Add(
                "PlacementAssistance", new System.Web.Routing.Route("PlacementAssistance.html",
                                    new RouteHandler("~/PlacementAssistance.aspx")));
    }

路由处理程序.cs :

    public RouteHandler(string virtualPath)
    {
        _virtualPath = virtualPath;
    }
    public IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        var display = BuildManager.CreateInstanceFromVirtualPath(
                        _virtualPath, typeof(Page)) as IDisplay;
        return display;
    }
     string _virtualPath;

IDisplay.cs :

public interface IDisplay : IHttpHandler
{
}

网络配置:

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="Session" />
      <add name="Session" type="System.Web.SessionState.SessionStateModule" preCondition="" />
    </modules>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <remove name="UrlRoutingHandler" />
    </handlers>
    <rewrite>
      <rules>
        <remove name="Plesk. SEO-safe redirect for http://www.theprojectjugaad.com" />
        <rule name="Plesk. SEO-safe redirect for http://www.theprojectjugaad.com" enabled="false" patternSyntax="Wildcard" stopProcessing="true">
          <match url="*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="www.theprojectjugaad.com" />
            <add input="{HTTPS}" pattern="OFF" />
          </conditions>
          <serverVariables />
          <action type="Redirect" url="http://theprojectjugaad.com/{R:1}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>

将框架从 2.0 升级到 4.0 后,URL 重写显示 404 错误

什么是不起作用的 URL?

我看到的是您已将 URL 从 .html 更正为 .aspx并且它可以工作。