Ajax call webmethod with friendly URL

3

I do not know if it's a frequent question, or something that is not possible. During my studies I realized that it was possible to do this with PHP, but I did not see anything with ASP.NET Web Forms.

I made a URL from the same page:

 routes.MapPageRoute("Pagina de Teste",
            "teste-usuario.com",
            "~/teste.aspx");

When I pass the page teste-usuario.com it loads teste.aspx .

My question is as follows, I have an AJAX method.

jQuery.ajax({
            type: "POST",
            data: "objeto",
            url: "teste.aspx/metodoTeste",
            contentType: "application/json; charset=utf-8",
            dataType: "json",

Being metodoTeste my WebMethod and teste.aspx where this method is located.

I wonder if it is possible to pass my friendly URL (test-user.com) instead of teste.aspx to load the same page. I would not like to make the page name visible (test.aspx).

    
asked by anonymous 03.03.2016 / 14:50

1 answer

1

Create a rewrite rule where .aspx suffix can be hidden.

Example (web.config):

   <rule name="Append .aspx">
        <match url="^((.*\/)?[^/.]+)$" />
        <action type="Rewrite" url="{R:1}.aspx" />
   </rule>

A http://seu.site/teste.aspx page can be accessed as http://seu.site/teste .

In the parameterized URL, using the question script as an example:

url: "teste.aspx/metodoTeste",

I would trade for this:

url: "teste/metodoTeste",
    
08.03.2016 / 20:18