2

I need to create db driven meta keywords/description. I would store these records in a database, xml format i presume; since it would be per culture.

How would i go about doing this?

any feedback, suggestions, help, greatly appreciated. thanks

4

4 回答 4

5

What you need to change is just the call to method that returns the keywork/description

You can use Thread.CurrentThread.CurrentUICulture to determine the user culture.

You need to change at web.config to auto change the culture.

Ex.: (Web.Config)

<globalization uiCulture="auto" culture="auto" />

(Controller)

ViewBag.Description = GetDescription(pageId, Thread.CurrentThread.CurrentUICulture.Name)

(View)

<meta name="description" content="@ViewBag.Description ">
于 2011-02-10T09:33:28.100 回答
4

Make a parent interface for all your model objects. and you could have:

public interface IBaseMasterViewDto
{
    int PageId { get; set; }
    string Title { get; set; }
    string MetaKeywords { get; set; }
    string MetaDescription { get; set; }
}

Thus in your master view you could use

<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage<IBaseMasterViewDto>" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">

  <head>
    <title><%: Model.Title %></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <meta name="keywords" content="<%: Model.MetaKeywords %>" />
    <meta name="description" content="<%: Model.MetaDescription %>" />

Hope it helps.

于 2011-02-10T09:46:48.810 回答
1

1 - Get keywords/description (from your Model) in your controller
2 - Assign them to a Viewbag property 3 - Display the viewbag property in your layout (or view)

OR

Assign your model with keywords/description and give it to your view as a parameter in your controller.

About the culture :
You just have to put it as a parameter in your method controller (and in your route).
After that, you have to give this parameter to your method retrieving keywords/description.

于 2011-02-10T09:29:44.167 回答
1

Shane,

I answered a somewhat similar question here on SO a while back. I didn't cover the cultural elements, but fujiy's answer above goes towards that in a way. Also, alexl's interface is a FAR better solution to loose typed viewdata elements (as per my answer in the similar question). anyway, here's what i answered 'on the day' for that question:

MVC and Meta Tags for Search Engine Optimization

于 2011-02-10T10:35:15.777 回答