Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have added this code to my global.asax
C#
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");
    }

And here's my web.config

XML
<?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>

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.
Posted
Updated 13-May-13 18:54pm
v2

1 solution

The routes wasn't being registered properly. Deleted the global.asax file and added it again and the code worked.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900