Hide URL parameter in MVC 5

Asked

Viewed 2,055 times

1

My question is this::

How to hide the URL ID parameter using routes or mask?

PessoaFisica/Edit/1 

for

PessoaFisica/Edit


        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });

1 answer

1


I will discuss in response some ways and recommend a.

1. Using slugs (recommended)

I speak of it in these answers:

The principle is to use another parameter to identify the person and pass it on the route. CPF, for example, is a good candidate. The name may be another candidate, but then we need to choose some way to undo ambiguities in case of double names.

2. Using POST

This is not a good way because, to access a record, you will always need to submit a form, validate it, to just forward the user to the edit screen.

3. Using an encoded variable

This resembles method 1, but implies some extra implementation. The idea is a URL like this:

/PessoaFisica/Acao/?codigo=A2B7649C100DB2F641

Using some reversible encryption algorithm, you can mask the id and the action to be executed within the encrypted variable.

Although it works, it is more disadvantageous than the Slug for not being intuitive.

  • 1

    OK friend! I will use option 3 even. I thought of using Guid but it is not usual in the bank!

Browser other questions tagged

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