locked
ajax does not work while using url rewrite RRS feed

  • Question

  • User448619955 posted

    hi there,i'm using ajax in my app.

    there is an issue while using url rewrite:

    <rule>
       <match url="(.*)">
       <conditions>
          <add matchType="IsFile" negate="true" />
          <add matchType="IsDirectory" negate="true" />
       </conditions>
       <action type="Rewrite" url="{R:1}.aspx"/>
    </rule>

    as soon as I remove above codes,everything goes well.

    I want to remove .aspx extension in every page.

    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:DropDownList ID="DropDownList1" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true" runat="server">
                    <asp:ListItem Value="0" Text="test"></asp:ListItem>
                    <asp:ListItem Value="1" Text="test"></asp:ListItem>
                </asp:DropDownList>
                <asp:Button ID="Button1" Visible="false" runat="server" Text="Button" />
            </ContentTemplate>
       </asp:UpdatePanel>
        <div>
        </div>
        </form>
    </body>
    </html>
    

    Saturday, July 25, 2015 5:40 AM

Answers

  • User177399542 posted

    Hi vahid.ch

    If you only want to remove .aspx from all the pages, best option is to use Friendly urls. Check this:

    http://www.hanselman.com/blog/IntroducingASPNETFriendlyUrlsCleanerURLsEasierRoutingAndMobileViewsForASPNETWebForms.aspx

    I have tested it with update panels and it works great. 

    Here are some basic steps:

    1. Install friendly urls from nuget.
      https://www.nuget.org/packages/Microsoft.AspNet.FriendlyUrls/
    2. Make changes in add global.asax file in your website and do changes as mentioned in readme.txt file. Here is complete code:
      <%@ Application Language="C#" %>
      <%@ Import Namespace="System.Web.Routing" %>
      <%@ Import Namespace="Microsoft.AspNet.FriendlyUrls" %>
      <script RunAt="server">
      
          void Application_Start(object sender, EventArgs e)
          {
              // Code that runs on application startup
              RouteConfig.RegisterRoutes(RouteTable.Routes);
      
          }
      
          void Application_End(object sender, EventArgs e)
          {
              //  Code that runs on application shutdown
      
          }
      
          void Application_Error(object sender, EventArgs e)
          {
              // Code that runs when an unhandled error occurs
      
          }
      
          void Session_Start(object sender, EventArgs e)
          {
              // Code that runs when a new session is started
      
          }
      
          void Session_End(object sender, EventArgs e)
          {
              // Code that runs when a session ends. 
              // Note: The Session_End event is raised only when the sessionstate mode
              // is set to InProc in the Web.config file. If session mode is set to StateServer 
              // or SQLServer, the event is not raised.
      
          }
      
          public static void RegisterRoutes(RouteCollection routes)
          {
              routes.EnableFriendlyUrls();
      
              // Put any additional route registrations here.
          }
             
      </script>
      
    3.  When you install friendly url package from nuget it will add some files :

      Site.Mobile.Master
      Site.Mobile.Master.designer.cs
      ViewSwitcher.ascx
      ViewSwitcher.ascx.designer.cs

      You can delete thiese files if not required.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 27, 2015 1:48 AM
  • User1724605321 posted

    Hi vahid ,

    vahid.ch

    there is an issue while using url rewrite:

    When you use the URL Rewrite module to rewrite the URL for a page that contains one or more UpdatePanel controls, the control will use the rewritten URL for all the actions that are performed by that UpdatePanel control. This can cause the controls in the UpdatePanel control to not work correctly, especially in cases when URL rewriting changes the directory hierarchy of the requested URL ,you could try setting the action URL to the original URL :

    protected void Page_Load(object sender, EventArgs e) 
    { 
        form1.Action = Request.RawUrl; 
    }
    

    Please refer to articles below for more details :

    http://forums.iis.net/t/1152547.aspx .

    http://www.iis.net/learn/extensions/url-rewrite-module/url-rewriting-for-aspnet-web-forms#AJAX_UpdatePanel .

    In addition ,you could also use URL Routing to achieve your requirement . Please click here for tutorial .

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 27, 2015 3:43 AM

All replies

  • User177399542 posted

    Hi vahid.ch

    If you only want to remove .aspx from all the pages, best option is to use Friendly urls. Check this:

    http://www.hanselman.com/blog/IntroducingASPNETFriendlyUrlsCleanerURLsEasierRoutingAndMobileViewsForASPNETWebForms.aspx

    I have tested it with update panels and it works great. 

    Here are some basic steps:

    1. Install friendly urls from nuget.
      https://www.nuget.org/packages/Microsoft.AspNet.FriendlyUrls/
    2. Make changes in add global.asax file in your website and do changes as mentioned in readme.txt file. Here is complete code:
      <%@ Application Language="C#" %>
      <%@ Import Namespace="System.Web.Routing" %>
      <%@ Import Namespace="Microsoft.AspNet.FriendlyUrls" %>
      <script RunAt="server">
      
          void Application_Start(object sender, EventArgs e)
          {
              // Code that runs on application startup
              RouteConfig.RegisterRoutes(RouteTable.Routes);
      
          }
      
          void Application_End(object sender, EventArgs e)
          {
              //  Code that runs on application shutdown
      
          }
      
          void Application_Error(object sender, EventArgs e)
          {
              // Code that runs when an unhandled error occurs
      
          }
      
          void Session_Start(object sender, EventArgs e)
          {
              // Code that runs when a new session is started
      
          }
      
          void Session_End(object sender, EventArgs e)
          {
              // Code that runs when a session ends. 
              // Note: The Session_End event is raised only when the sessionstate mode
              // is set to InProc in the Web.config file. If session mode is set to StateServer 
              // or SQLServer, the event is not raised.
      
          }
      
          public static void RegisterRoutes(RouteCollection routes)
          {
              routes.EnableFriendlyUrls();
      
              // Put any additional route registrations here.
          }
             
      </script>
      
    3.  When you install friendly url package from nuget it will add some files :

      Site.Mobile.Master
      Site.Mobile.Master.designer.cs
      ViewSwitcher.ascx
      ViewSwitcher.ascx.designer.cs

      You can delete thiese files if not required.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 27, 2015 1:48 AM
  • User-693045842 posted

    Hi vahid ,

    vahid.ch

    there is an issue while using url rewrite:

    check link below:

    http://www.iis.net/downloads/microsoft/url-rewrite .

    http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module .

    lemo

    Monday, July 27, 2015 3:38 AM
  • User1724605321 posted

    Hi vahid ,

    vahid.ch

    there is an issue while using url rewrite:

    When you use the URL Rewrite module to rewrite the URL for a page that contains one or more UpdatePanel controls, the control will use the rewritten URL for all the actions that are performed by that UpdatePanel control. This can cause the controls in the UpdatePanel control to not work correctly, especially in cases when URL rewriting changes the directory hierarchy of the requested URL ,you could try setting the action URL to the original URL :

    protected void Page_Load(object sender, EventArgs e) 
    { 
        form1.Action = Request.RawUrl; 
    }
    

    Please refer to articles below for more details :

    http://forums.iis.net/t/1152547.aspx .

    http://www.iis.net/learn/extensions/url-rewrite-module/url-rewriting-for-aspnet-web-forms#AJAX_UpdatePanel .

    In addition ,you could also use URL Routing to achieve your requirement . Please click here for tutorial .

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 27, 2015 3:43 AM