Routing ASP.NET 4.0 URL路由HTTP错误404.0-未找到

Routing ASP.NET 4.0 URL路由HTTP错误404.0-未找到,routing,asp.net-4.0,Routing,Asp.net 4.0,我已经在ASP.NET 4.0中使用以下路由实现了URL路由 routes.MapPageRoute( "NewsDetails", // Route name "news/{i}/{*n}", // Route URL "~/newsdetails.aspx" // Web page to handle route ); 这给了我类似的url http://www.mysie.com/news/1/this-is-test-n

我已经在ASP.NET 4.0中使用以下路由实现了URL路由

routes.MapPageRoute(
   "NewsDetails",               // Route name
   "news/{i}/{*n}",  // Route URL
   "~/newsdetails.aspx"      // Web page to handle route
    );
这给了我类似的url

http://www.mysie.com/news/1/this-is-test-news
这在我的本地主机上运行良好

但当我把它上传到服务器上时,它给出了

Server Error

404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, 
or is temporarily unavailable.
如果我尝试,它会显示第页

有人有同样的问题吗

如何设置URL
要在windows server 2008上工作?

要使用IIS 7.5启用默认的ASP.Net 4.0路由,请执行以下操作:

  • 确保已安装HTTP重定向功能 可以完成->控制面板->程序->关闭windows功能->万维网服务->通用HTTP功能->HTTP重定向
  • 用下面的代码修改您的
    web.config
  • 
    
    三,。在
    global.asax
    文件中创建路由

    注意:您必须将应用程序池设置为Asp.net 4.0应用程序池,因为路由不适用于Asp.net 4.0经典应用程序池。


    希望这会有所帮助。

    我已经阅读了你所有的食谱,但是我的网站(ASP.NET 4.0+VS2010+Cassini)仍然没有正确的路由

    我的站点的虚拟路径是“CompanyName.ApplicationName.Web”。我把这个虚拟文件改成了“MyApplicationName”,瞧

    更改卡西尼号的虚拟路径配置:

    • 卡西尼的虚拟路径->Ctrl+W,P或
    • 右键单击网站和“属性窗口”

    我的解决方案,在尝试了一切之后:

    糟糕的部署,一个旧的预编译app.config挂在我的部署位置上,使一切都无法工作

    我的最终设置有效:

    • IIS 7.5,Win2k8r2 x64
    • 集成模式应用程序池
    • web.config中没有任何更改-这意味着没有用于路由的特殊处理程序。这是我的快照,有很多其他文章参考。我正在使用FluorineFX,因此我添加了该处理程序,但我不需要任何其他处理程序:

      <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <authentication mode="None"/>
      
        <pages validateRequest="false" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
        <httpRuntime requestPathInvalidCharacters=""/>
      
        <httpModules>
          <add name="FluorineGateway" type="FluorineFx.FluorineGateway, FluorineFx"/>
        </httpModules>
      </system.web>
        <system.webServer>
          <!-- Modules for IIS 7.0 Integrated mode -->
          <modules>
            <add name="FluorineGateway" type="FluorineFx.FluorineGateway, FluorineFx" />
          </modules>
      
          <!-- Disable detection of IIS 6.0 / Classic mode ASP.NET configuration -->
          <validation validateIntegratedModeConfiguration="false" />
        </system.webServer>
      
    • PassthroughRouteHandler.cs-这实现了从到的自动转换,然后将由default.aspx处理:

      public class PassthroughRouteHandler : IRouteHandler {
      
          public IHttpHandler GetHttpHandler(RequestContext requestContext) {
              HttpContext.Current.Items["IncomingMessage"] = requestContext.RouteData.Values["message"];
              requestContext.HttpContext.Response.Redirect("#" + HttpContext.Current.Items["IncomingMessage"], true);
              return null;
          }
      }
      

    带有路径的文件是否与aspx页面的文件位于同一目录中?否。我的aspx文件位于根文件夹中这应该是
    UrlRoutingHandler 2.0.0
    ?为什么不是4.0?这对我来说很有效,但我不需要添加UrlRoutingHandler节点。我遇到了类似的情况,但这个asnwer不起作用,请看一看:很高兴我找到了这个答案!我使用的虚拟路径中有句点“”。将我的虚拟路径从“mysite.com”更改为“mysite”后,我所有的自定义路由都正常工作。
    void Application_Start(object sender, EventArgs e) {
        // Register routes...
        System.Web.Routing.Route echoRoute = new System.Web.Routing.Route(
              "{*message}",
            //the default value for the message
              new System.Web.Routing.RouteValueDictionary() { { "message", "" } },
            //any regular expression restrictions (i.e. @"[^\d].{4,}" means "does not start with number, at least 4 chars
              new System.Web.Routing.RouteValueDictionary() { { "message", @"[^\d].{4,}" } },
              new TestRoute.Handlers.PassthroughRouteHandler()
           );
    
        System.Web.Routing.RouteTable.Routes.Add(echoRoute);
    }
    
    public class PassthroughRouteHandler : IRouteHandler {
    
        public IHttpHandler GetHttpHandler(RequestContext requestContext) {
            HttpContext.Current.Items["IncomingMessage"] = requestContext.RouteData.Values["message"];
            requestContext.HttpContext.Response.Redirect("#" + HttpContext.Current.Items["IncomingMessage"], true);
            return null;
        }
    }