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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:47:23+00:00 2026-05-18T10:47:23+00:00

I was wondering what, if there is one, is the best practice for including

  • 0

I was wondering what, if there is one, is the best practice for including SEO content such as meta descriptions and keywords in an ASP.NET MVC (I’m using v3 RC) view. My initial plan is to create an actionfilter, applied globally to actions, to pull the relevant data from a data store and pass it as viewdata to the view.

My questions are:
1) Do you foresee any problems with this approach?
2) Are there any more suitable approaches?
3) what is an appropriate data store to use here – should i pull from the DB (or cache if the data is available), use resource files, config files, etc?

Thanks in advance,

JP

  • 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-18T10:47:24+00:00Added an answer on May 18, 2026 at 10:47 am

    I would use attributes on my controller actions and add them to the ViewData in my base controller in the method OnExecutingAction.

    The motivation to put it in the controller and not the view is that it’s really more information about the actual action than about the view. And you can use it when returning different kinds of formats like json or xml.

    Controller

    class MyController
    {
    
      [MetaKeywords("hello,world,something,else")]
      [MetaDescription("Tells you how to greet the world")]
      ActionResult Hello()
      {
          return View();
      }
    }
    

    You could always use a resource file instead of plain strings.

    in base controller:

        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var keywords = filterContext.ActionDescriptor.GetCustomAttributes(typeof(MetaKeywordsAttribute), false);
            if (keywords.Length == 1)
                ViewData["MetaKeywords"] = keywords.Value;
    
            var description = filterContext.ActionDescriptor.GetCustomAttributes(typeof(MetaDescriptionAttribute), false);
            if (description.Length == 1)
                ViewData["MetaDescription"] = description.Value;
    
            base.OnActionExecuting(filterContext);
        }
    

    In your layout

    <meta name="keywords" value="@View.MetaKeywords" />
    

    And here is the answers your questions: =)

    1) Do you foresee any problems with this approach?

    Nope. It’s a fine approach.

    2) Are there any more suitable approaches?

    Just gave you an alternative.

    3) what is an appropriate data store to use here – should i pull from the DB (or cache if the data is available), use resource files, config files, etc?

    I would put it in plain text (if you don’t have to support multiple languages), else in a resource file. This information is typically not changed unless the view or controller is changed (where a recompilation is needed anyway). Hence no need for a more dynamic source.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering if there's a preferred method or Best Practice for storing Updated By
I was wondering, is there a best practice to write an OSX programm that
Where can I find some good pointers on best practices for running ASP.NET MVC
I am wondering if there is a library one can use that calculates elapsed
I'm using Tkinter, and I'm wondering if there is a way to define one
I am wondering how to build a join table articles_categories, but one where there
I was wondering, is there a way to make a kind of one to
I am wondering what's the best practice to parse XML like this: <root> <MailNotification
Coming from Java, I'm wondering if a Java best practice applies to JavaScript. In
I was wondering, what is the best practice. To convert all utf-8 special characters

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.