简体   繁体   中英

URL routing in asp.net 4.0 web form not working

I am not able to figure it out how to make it work, searched all over internet.. here is my code

  void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        RegisterRoutes(RouteTable.Routes);
    }
void RegisterRoutes(RouteCollection routes)
    {
        //routes.MapPageRoute("Default", "agent/{name}", "~/agent/default.aspx");
        routes.MapPageRoute("Default", "agent/{name}", "~/agent/default.aspx", false, new RouteValueDictionary { { "name", String.Empty } });
    }

My Web.config file

 <system.web>
    <compilation debug="true" targetFramework="4.0" >
      <assemblies>
        <add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

      </assemblies>
    </compilation>

    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
    </authentication>
    <membership>
      <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
             applicationName="/" />
      </providers>
    </membership>

    <profile>
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
      </providers>
    </profile>`enter code here`

    <roleManager enabled="false">
      <providers>
        <clear/>
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>
    <customErrors mode="Off"/>
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">

    </modules>
    <modules>
      <remove name="UrlRoutingModule" />
      <add name="UrlRoutingModule"
           type="System.Web.Routing.UrlRoutingModule, 
               System.Web.Routing, 
               Version=4.0.0.0, 
               Culture=neutral, 
               PublicKeyToken=31BF3856AD364E35"/>
    </modules>
  </system.webServer>
</configuration>

I searched alot over internet for asp.net web form routing, done all the step etc but not able to make it work. any help will be very thankful .

try this web.config

<system.webServer>
  <validation validateIntegratedModeConfiguration="false" />
  <modules runAllManagedModulesForAllRequests="true">
      <remove name="UrlRoutingModule" />
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </modules>
  <handlers>
      <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
</system.webServer>

In my case I didn't copy following file on server:

PrecompiledApp.config

after adding it, & restarting IIS worked form.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM