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

  • SEARCH
  • Home
  • 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 6782923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:48:08+00:00 2026-05-26T16:48:08+00:00

In my MVC 3 solution I want to have all Ids in querystring to

  • 0

In my MVC 3 solution I want to have all Ids in querystring to be crypted. To decrypt URLs I inherited from DefaultModelBinder and overrided BindProperty method:

 public class CryptedIdBinder : DefaultModelBinder
{   

    protected override void BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor)
    {
        if (propertyDescriptor.Name.ToLower() == "id")
        {
            propertyDescriptor.SetValue(bindingContext.Model, CryptoHelper.Decrypt(controllerContext.HttpContext.Request.Form["id"]));
            return;
        }

        base.BindProperty(controllerContext, bindingContext, propertyDescriptor);
        return;
    }

After that I set new DefaultBinder in global.asax on Application_Start:

System.Web.Mvc.ModelBinders.Binders.DefaultBinder = new CryptedIdBinder();

I didn’t inherit from IModelBinder because I want to change binding logic only for id fields in solution.

The issue is that BindProperty method is never called. What am I doning wrong?

PS. In order to be sure that I call at least BindModel method I added a peace of this code inside my custom binder, and it was hit by the debugger:

public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        return base.BindModel(controllerContext, bindingContext);
    }
  • 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-05-26T16:48:09+00:00Added an answer on May 26, 2026 at 4:48 pm

    If your models don’t have Id properties of course the BindProperty won’t be called. Because it called on the model properties. If I understood your question what you need is to transform each Id named query string parameter. In this case you need a custom value provider instead of a modelbinder. This is good article about the value providers. And it’s quite easy to write one:

    public class MyValueProviderFacotry : ValueProviderFactory
    {
        public override IValueProvider GetValueProvider(ControllerContext controllerContext)
        {
            return new MyValueProvider(controllerContext);
        }
    }
    
    public class MyValueProvider : IValueProvider
    {
        private ControllerContext controllerContext;
    
        public MyValueProvider(ControllerContext controllerContext)
        {
            this.controllerContext = controllerContext;
        }
    
        public bool ContainsPrefix(string prefix)
        {
            return true;
        }
    
        public ValueProviderResult GetValue(string key)
        {
            if (key.ToLower() == "id")
            {
               var originalValue =  controllerContext.HttpContext.Request.QueryString[key]; 
               var transformedValue = CryptoHelper.Decrypt(orignalValue );
               var result = new ValueProviderResult(transformedValue,originalValue,CultureInfo.CurrentCulture);
                return result;
            }
            return null;
        }
    }
    

    In global.asax:

     protected void Application_Start()
            {
                AreaRegistration.RegisterAllAreas();
                ValueProviderFactories.Factories.Insert(4, new MyValueProviderFacotry()); //Its need to be inserted before the QueryStringValueProviderFactory
                RegisterGlobalFilters(GlobalFilters.Filters);
                RegisterRoutes(RouteTable.Routes);
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Going mad now. I have a MVC solution that i've upgraded from MVC 1
We have an ASP.Net MVC solution built in VS2008 and TFS2008. We use TFS
We have an ASP.Net MVC 1.0 solution developed using Visual Studio 2008 and .net
Does anyone have the issue with Resharper where opening a solution with MVC projects
I had a working solution using ASP.NET MVC Preview 3 (was upgraded from a
I have a new solution that is an ASP.NET MVC 2.0 application. I have
I have a Class Library project and MVC project in the one solution. My
I have an MVC 3 application with all texts in a SQL database. The
Is it possible to have one .NET MVC application, and have it accessible from
I have a Visual Studio 2010 MVC 3 web solution containing a number of

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.