Click here to Skip to main content
14,428,476 members
Rate this:
Please Sign up or sign in to vote.
See more:
How to hide Url parameter in ASP.Net MVC4 ?


I am working on Asp.Net MVC. when i click the action link i navigate to UserDetails.cshtml page that is fine but the Url is like this

localhost:8080//Admin/UserDetails/5.

i don't want to show the Id in URL i want URL when i click actionlink will be like this

localhost:8080//Admin/UserDetails/

any suggestions ??
Posted
Updated 29-Mar-19 7:16am
v2
Comments
Dharmesh .S. Patil 5-Oct-15 5:00am
   
It is not possible to do what you want. In that if you want to be able to access the Id from your controller the you must pass the Id as part of your URL - you cannot access something that does not exist.
Philippe Mori 9-Oct-15 12:19pm
   
You can somehow hide it by using a frame or loading content using javascript or using hidden fields but you won't have support for that and it would not be possible to bookmark a page...
Rate this:
Please Sign up or sign in to vote.

Solution 1

You can't hide url parameters. If the reason you want the parameter hidden is so that people can't access ids they are not authorised to, then the solution is to amend your code so that people only access data they are authorised to access.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

You cannot hide this parameter.

Use POST instead of GET calls to remove parameters from url.
You will still be able to see the parameter in the request message.

The only way to safely hide the parameter is to encrypt it.
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 3

Hi Shiva
you have to implement URL Rooting Concept to hide your URL parameter.

Please find the solution to click link below.


http://www.dotnetcurry.com/aspnet-mvc/814/routing-aspnet-mvc[^]
   
Rate this:
Please Sign up or sign in to vote.

Solution 5

I have one update for you,if you refresh your page the tempdata value gets flushed hence use session instead of tempdata------

instead of
TempData["id"] = id;

use

Session["id"=id;

Thank you
   
v2
Comments
[no name] 21-Dec-16 8:12am
   
Exactly how many times do you have to answer the same already answered question?
Rate this:
Please Sign up or sign in to vote.

Solution 6

I have one update for you,if you refresh your page the tempdata value gets flushed hence use session instead of tempdata------

instead of
TempData["id"] = id;

use

Session["id"=id;




Thank You
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

Yes,you can hide parameters...............


1) you have to write one method to get this parameters

public ActionResult GetId(int id=0)
{
TempData["id"] = id;
return RedirectToAction("UserDetails");
}


2) Now use this parameters in your UserDetails method

public ActionResult UserDetails()
{
id=int.Parse(TempData["id"].toString());
}
3)And Instead of calling UserDetails method in your Index View,Call GetId
   
Comments
alikipel 8-Dec-16 1:35am
   
If your refresh the page what happen? friend
Answer is bloww:)
Abhishek Prakash Dixit 21-Dec-16 6:51am
   
I have one update for you,if you refresh your page the tempdata value gets flushed hence use session instead of tempdata------

instead of
TempData["id"] = id;

use

Session["id"=id;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100