当托管在根目录上时,Asp.net路由不起作用

当托管在根目录上时,Asp.net路由不起作用,asp.net,url-rewriting,routing,asp.net-routing,Asp.net,Url Rewriting,Routing,Asp.net Routing,我使用Asp.NET4.0路由技术来实现友好的URL。我在global.asax中使用了以下代码 void Application_Start(object sender, EventArgs e) { RegisterRoutes(RouteTable.Routes); } void RegisterRoutes(RouteCollection routes) { string connectionstring = System.Configuration.Configur

我使用Asp.NET4.0路由技术来实现友好的URL。我在global.asax中使用了以下代码

void Application_Start(object sender, EventArgs e)
{
    RegisterRoutes(RouteTable.Routes);
}

void RegisterRoutes(RouteCollection routes)
{

    string connectionstring = System.Configuration.ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    SqlConnection sqlCon = new SqlConnection(connectionstring);
    SqlCommand sqlCmd = new SqlCommand("Sch_Sp_GetRegisterRoutes", sqlCon);
    sqlCmd.CommandType = CommandType.StoredProcedure;

    SqlDataAdapter sda = new SqlDataAdapter(sqlCmd);
    DataTable dt = new DataTable();

    try
    {
        sda.Fill(dt);
    }
    catch (Exception ex)
    {
    }
    finally
    {
        sqlCon.Close();

    }
    if (dt != null && dt.Rows.Count > 0)
    {
        foreach (DataRow dr in dt.Rows)
        {
            try
            {
                routes.MapPageRoute(dr["Menuname"].ToString().Replace(" ",string.Empty),
              dr["URL"].ToString(),
               "~/" + dr["Pagename"].ToString());
            }
            catch (Exception exx)
            {

            }

        }
    }


}
我在数据库中的url类似于About Us,Pagename类似于MyFolder/Aboutus.aspx。在我的本地计算机上,它工作正常,但当我在服务器(iis 7版本和windows server 2008)上部署它时,它显示错误' 404-找不到文件或目录。 您正在查找的资源可能已被删除、名称已更改或暂时不可用' 我把它叫做resolveUrl(“~/关于我们”)。
请帮助我……

只需在web.config中添加几行代码,它就会对我起作用

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
        <remove name="UrlRoutingModule-4.0" />
        <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
        <remove name="Session"/>
        <add name="Session" type="System.Web.SessionState.SessionStateModule" preCondition=""/>
    </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>

您不需要(或不希望)运行AllManagedModulesForallRequests=“true”