Which is faster? Search given on the Bank or reading a cookie?

0

Well, in your opinion, what would be best in this situation?

I'm working on an Asp MVC and Entity Framework site. I have a table of federative units where I have (simplifying) 3 columns Id, StateName, StateName. Example: 1, Minas Gerais, Minas Gerais.

There is a state search, where the user selects the state in a listbox and sends the request, containing the State Id for a Search Routing Action.

If this action receives other data for example a city, it will redirect to the action that returns the url with the city MySite / State / City.

If you only receive the state (the case that interests us here) it will be redirected to the action that returns the url with just the state, for example: MySite / minasgerais

Simple, right?

The (simplified) signature of these actions would be:

public ActionResult Busca(int estado = 0, int cidade = 0 ...)
public ActionResult Estado(string urlEstado)

But notice that I get an id. And when forwarding the action it asks for a string with the url. Why not if the url would be MySite / 1 which is not user friendly. Then I look for the url in the bank and redirecino. Okay.

But in the state action I need the Id of this state. Then comes my doubt. It would be faster in terms of performance for the site, fetching the Id in the database through the url (which is also unique). Or read a cookie saved in the action Search containing just the id?

I read the cookie like this:

HttpCookie Cookie = Request.Cookies[Nome];
return Server.UrlDecode(Cookie.Values.Get(chaveValoresCookie));

And reading from the bank would be:

int id = ctx.tbEstado.where(e => e.Url == url).select(e => e.Id).FirstOrDefalt();
    
asked by anonymous 13.01.2018 / 18:11

0 answers