Ajax call webmethod with friendly URL

Asked

Viewed 499 times

3

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

I made a URL of the same page:

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

When I turn the page teste-usuario.com she carries the teste.aspx.

My question is this, 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 user-friendly URL (test-user.com) instead of teste.aspx to load the same page. I would not like to leave the page name visible (test.aspx).

  • I have another default document, and wanted to do the same but for several pages, calling by the created friendly url understands?

1 answer

1

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

Example (web.config):

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

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

In the URL with parameters, using as an example the question script:

url: "teste.aspx/metodoTeste",

I’d trade for that:

url: "teste/metodoTeste",
  • I tried too, I think this scheme does not work in javascript.

  • What I wanted was to call the Webmethod through a friendly url and not the page’s first name.

  • This yes, but I just wanted to call it another way for more security, but no problem, if I’m not mistaken in php it is possible to call through a friendly url instead of the page’s own name.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.