簡體   English   中英

asp.net 4.0 Web表單中的URL路由不起作用

[英]URL routing in asp.net 4.0 web form not working

我無法弄清楚如何使其工作,通過互聯網進行了搜索..這是我的代碼

  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 } });
    }

我的Web.config文件

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

我在Internet上搜索了很多asp.net Web表單路由,完成了所有步驟等,但無法使其正常工作。 任何幫助都會非常感謝。

試試這個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>

就我而言,我沒有在服務器上復制以下文件:

PrecompiledApp.config

添加后,重新啟動IIS工作表。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM