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 7926867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:59:30+00:00 2026-06-03T18:59:30+00:00

I have a publicly available controller (The action cannot be hidden under any security

  • 0

I have a publicly available controller (The action cannot be hidden under any security attribute) . The controller has an action which is available publicly as well.

Following is a sample structure of the controller :

 public SomeController : Controller {


       [HttpGet] 
       public ActionResult show(int id){

       }

 }

The action has a id field which is required. However throws an error which unnecessary adds to the logs when someone enters a malformed URL without the required id (or when search engine bots hit the a URL with the required id).

What should be the ideal solution to deal with this solution.

Possible solutions that come to my mind are :

  • Set the id as Nullable (int? id) and explicitly handle the case of not having a value by redirecting the caller to some other page showing appropriate errors
  • explicitly send a 404 error

Is there a generic way using Attributes to do this?

P.S : (to be specific) by explicit I mean writing if else conditions to handle such cases per controller.

I would appreciate any hints in the right direction.

  • 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-03T18:59:49+00:00Added an answer on June 3, 2026 at 6:59 pm

    You need a route constraint. This will help the router throw out URLs earlier (resulting in a 404) rather than later (the route is valid, goes to action, action barfs because a parameter is missing).

    http://www.asp.net/mvc/tutorials/controllers-and-routing/creating-a-route-constraint-cs

    Example default route (potentially replacing the existing one in your global.asax.cx):

    // order is important; more specific routes to less specific routes is what you want
    //
    // default index action, with no ID
    routes.MapRoute(
        "Default_Index",
        "{controller}/",
        new {controller="Home", action="Index"}
     );
    
    // default create action, with no ID
    routes.MapRoute(
        "Default_Create",
        "{controller}/Create",
        new {controller="Home", action="Create"}
     );
    
    // default action requiring an ID (such as EDIT)
    routes.MapRoute(
        "Default",
        "{controller}/{action}/{id}",
        new {controller="Home", action="Index"},
        new {id = @"\d+" }
     );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know of any publicly available Question answering applications which have built using
We have the need for the following kinds of services: Publicly available. User is
I have a personal Git repository which I don't want to have publicly available
Are there any publicly available libraries or APIs out there on Ubuntu that allow
I'm sure this is publicly available somewhere but my google-fu has failed me. What
I have a model that has an attribute that referrers to when this object
I have a static file that I don't want to be publicly available. Is
If I want to have a publicly accessible function on a jQuery plugin I'm
I have my dot files in Github publicly. This means that I have only
Have a matrix report now that has Position, Hours and Wages for a location

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.