【问题标题】:URL routing in asp.net 4.0 web form not workingasp.net 4.0 Web 表单中的 URL 路由不起作用
【发布时间】:2016-06-23 14:28:50
【问题描述】:

我无法弄清楚如何使它工作,在互联网上搜索.. 这是我的代码

  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>

我在互联网上搜索了很多 asp.net 网络表单路由,完成了所有步骤等,但无法使其工作。任何帮助将不胜感激。

【问题讨论】:

  • 向我们展示日志...您尝试了哪些 url,服务器甚至可以看到它们吗?
  • 我正在尝试localhost:40933/agnet/username 在哪里可以看到本地主机的登录信息?
  • 这取决于您如何设置 II。事件日志位于右键单击计算机图标选择管理。然后转到事件查看器。
  • 我看不到日志,事件查看器中有很多日志文件...
  • agnet 将不起作用,因为您的路线都使用agent。你把 n 和 e 颠倒了。您应该得到 401 并在 IIs 日志中看到错误的 URL。

标签: c# asp.net routing


【解决方案1】:

试试这个 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>

【讨论】:

    【解决方案2】:

    就我而言,我没有在服务器上复制以下文件:

    PrecompiledApp.config

    添加后,重新启动 IIS 工作表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-08
      • 2011-07-30
      • 1970-01-01
      • 1970-01-01
      • 2014-03-12
      • 2011-12-15
      • 1970-01-01
      相关资源
      最近更新 更多