【问题标题】:How to remove .aspx from the URL in IIS如何从 IIS 中的 URL 中删除 .aspx
【发布时间】:2015-01-20 05:10:56
【问题描述】:

如何从 IIS 中的 URL 中删除 .aspx? 我需要这个用于 SEO 目的,如果有人有想法,请指导我。

【问题讨论】:

  • 您是否尝试过在 google 中搜索此内容

标签: asp.net .net iis iis-7 url-redirection


【解决方案1】:

为此,您需要重写 URL。我没有亲自做过,所以不能提供任何样品。但是网上有大量的例子。

这是我找到的一个简单示例:ASP.NET rewriting URLs

【讨论】:

    【解决方案2】:

    看看使用 System.Web.Routing RouteCollection。您在应用程序启动时设置了一系列规则(即从 global.asax Application_Start 调用)。您可以将无扩展名的 URL 映射到站点中的实际页面,并处理页面中的 url 参数。

    在 global.asax 中:-

    using System.Web.Routing;
    

    。 . .

    RouteCollection routes = RouteTable.Routes;
    
    // simple route that maps /index to /index.aspx
    routes.MapPageRoute("home", "index", "~/index.aspx");
    
    // more complex route that handles parameters
    routes.MapPageRoute("products-category",
                        "products/{main-category}/{category}",
                        "~/pages/product-landing.aspx");
    

    处理页面中的 URL 参数(第二个示例):-

    using System.Web.Routing;
    

    。 . .

    protected override void OnLoad(EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string mainCategory = string.Empty,
                   subCategory  = string.Empty;
    
            if (RouteData.Values["main-category"] != null)
            {
                mainCategory = RouteData.Values["main-category"].ToString();
            }
    
            if (RouteData.Values["category"] != null)
            {
                subCategory = RouteData.Values["category"].ToString();
            }
    
            // and then do what you need to with those parameters..
    

    所以在本例中,如果有人请求http://yoursite.com/products/animals/monkeys/,那么您的main-category 将是动物,而category 将是猴子

    【讨论】:

      【解决方案3】:

      这可能是实现它的另一种方式。将其添加到 web.config 的 handlers 部分

      <add
          name="ExtensionlessUrl-ISAPI-4.0_32bit"
          path="*."
          verb="GET,HEAD,POST,DEBUG"
          modules="IsapiModule"
          scriptProcessor="%WINDIR%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll"
          preCondition="classicMode,runtimeVersionv4.0,bitness32" 
          responseBufferLimit="0" />
      <add
          name="ExtensionlessUrl-ISAPI-4.0_64bit"
          path="*." 
          verb="GET,HEAD,POST,DEBUG"
          modules="IsapiModule"   
          scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll"
          preCondition="classicMode,runtimeVersionv4.0,bitness64"
          responseBufferLimit="0" />
      <add 
          name="ExtensionlessUrl-Integrated-4.0" 
          path="*." verb="GET,HEAD,POST,DEBUG" 
          type="System.Web.Handlers.TransferRequestHandler" 
          preCondition="integratedMode,runtimeVersionv4.0" />
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-11-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-13
        • 2015-06-24
        • 1970-01-01
        相关资源
        最近更新 更多