Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7780279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:50:53+00:00 2026-06-01T18:50:53+00:00

When navigating to a new webpage, is there a Best Practice for passing Ids

  • 0

When navigating to a new webpage, is there a “Best Practice” for passing Ids around.

For example, a person registers to use a website, they get given an Id, this needs to be passed around the rest of the website/pages where it is used to retrieve relevant data from a database.

If the Id is passed in the url: http://myWebsite.com/User/Details/1234, the user could change it to
http://myWebsite.com/User/Details/4567 and potentially retireve a different user’s details.

Putting this value in a hidden field and then POSTing wouldn’t be great either as “view source” would display the value.

Many thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:50:54+00:00Added an answer on June 1, 2026 at 6:50 pm

    That’s why you should always verify that this id belongs to the currently authenticated user. The currently authenticated user is stored in the forms authentication cookie and is something that the user cannot change because the value is encrypted. This cookie is emitted when the user logs in and you can access it everywhere where you have an instance to HttpContextBase (which is pretty much almost anywhere in the V and C parts of the MVC pattern).

    For example, like this:

    [Authorize]
    public ActionResult Foo(int id)
    {
        string currentUser = httpContext.User.Identity.Name;
        // TODO: go ahead and check in your backed that the id 
        // belongs to the currently connected user
        ...
    }
    

    Obviously writing those checks over and over again in all controller actions could quickly become boring, not to mention the DRYness of the approach. That’s why it is recommended to write a custom Authorize attribute which will perform those checks before even entering into the controller action. Then you will decorate your controller actions with this custom attribute and you will know for sure that if the code has reached inside the action it means that the current user is the owner of the id passed as parameter. The way this id is passed as parameter doesn’t really matter. Could be route data, query string, POST, whatever. The user can modify it as much as he likes. The important part is that you ensure that the value he entered is coherent with your domain authorization logic.

    So:

    public class AuthorizeOwnerAttribute : AuthorizeAttribute
    {
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            var authorized = base.AuthorizeCore(httpContext);
            if (!authorized)
            {
                // the user is either not authenticated or not authorized
                // no need to continue any further
                return false;
            }
    
            // at this stage we know that the user is authenticated and
            // authorized (in roles), so let's go ahead and see who this 
            // user is
            string username = httpContext.User.Identity.Name;
    
            // now let's read the id. In this example I fetch it from
            // the route data but you could adapt according to your needs
            string id = httpContext.Request.RequestContext.RouteData.Values["id"] as string;
    
            // Now that we know the user and the id let's go ahead and 
            // check in our backend if the user is really the owner
            // of this id:
            return IsOwner(username, id);
        }
    
        private bool IsOwner(string username, string id)
        {
            // go ahead and hit the backend             
            throw new NotImplementedException();
        }
    }
    

    and then:

    [AuthorizeOwner]
    public ActionResult Foo(int id)
    {
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In C#, how do i create a new webpage that I can either use
I have an jQuery accordion for a form on an internal company website. They
I am currently coding an application that involves navigating between pivot control. There will
I'm very new to JavaScript, and I have a webpage with 3 nested frames
I'm relatively new to Obj-C and haven't got to the stage of navigating with
I'm looking at the following site: www.example.com I'm navigating to the site with a
Initially I am navigating from one to another XAML class like this (for example,
In Visual Studio 2010 Beta 2 I created a new navigation Silverlight application. Without
I'm new to AS3 and have been working on an XML driven navigation system
I am new to iphone development.I have created a UIBarButtonItem on the navigation bar.I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.