Click here to Skip to main content
15,561,948 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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...

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.
 
Share this answer
 
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.
 
Share this answer
 
v2
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[^]
 
Share this answer
 
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
 
Share this answer
 
v2
Comments
[no name] 21-Dec-16 8:12am    
Exactly how many times do you have to answer the same already answered question?
C#
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
 
Share this answer
 
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
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900