使用MapPageRoute的URL路由不能与asp.net webforms一起使用 [英] Url Routing with MapPageRoute is not working with asp.net webforms

查看:142
本文介绍了使用MapPageRoute的URL路由不能与asp.net webforms一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将此代码添加到我的global.asax

I have added this code to my global.asax

void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        RegisterRoutes(RouteTable.Routes);

    }

.........

void RegisterRoutes(RouteCollection routes)
    {
        routes.RouteExistingFiles = true;
        routes.MapPageRoute("Home", "Home", "~/Pages/Contents/Home.aspx");
    }



这里是我的web.config




And here''s my web.config

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="Test" connectionString="Data Source=DIZZY\SQLEXPRESS;Initial Catalog=VitaGamer;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False;"/>
  </connectionStrings>
  <system.web>
    <webServices>
      <protocols>
        <add name="HttpGet"/>
        <add name="HttpPost"/>
      </protocols>
    </webServices>
    <compilation debug="true" targetFramework="4.5">
      <assemblies>
        <add assembly="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </assemblies>
    </compilation>
    <httpRuntime targetFramework="4.5" relaxedUrlToFileSystemMapping="true"/>
    <pages controlRenderingCompatibilityVersion="4.0">
      <controls>
        <add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit"/>
      </controls>
    </pages>
  </system.web>
  <system.webServer>
    <defaultDocument enabled="true">
      <files>
        <add value="Default"/>
      </files>
    </defaultDocument>
    <modules runAllManagedModulesForAllRequests="true"/>
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit"/>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit"/>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0"/>
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0"/>
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
    </handlers>
  </system.webServer>
</configuration>



所以当我说http:// localhost:42115 / Home应该给我看http:// localhost:42115 / Pages / Contents / Home.aspx



但事实并非如此。相反,它正在向我显示



HTTP错误404.0 - 在IIS 8.0上找不到(快递)现在我有另一个网站,其工作与iis 8.0相当不错但在此基础上站点路由不起作用。应用程序池处于集成模式。它也不适用于visual studio 2012开发服务器。但是另一个网站呢。


So when I say http://localhost:42115/Home is supposed to show me http://localhost:42115/Pages/Contents/Home.aspx

But it''s not. Instead it''s showing me

HTTP Error 404.0 - Not Found on IIS 8.0 (express) Now I have another website with works pretty good with iis 8.0 but on this site routing is not working. Application pool is in integrated mode. It''s not working with visual studio 2012 development sever either. But the other website does.

推荐答案

这些路线没有被正确注册。删除了global.asax文件并重新添加,代码工作。
The routes wasn''t being registered properly. Deleted the global.asax file and added it again and the code worked.


这篇关于使用MapPageRoute的URL路由不能与asp.net webforms一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆