anonymous
anonymous

Reputation: 6885

ASP.NET MVC - Non-Embedded Resource FIle

I currently have a local resource file in an ASP.NET MVC project. The goal of this file is to let a non-programmer edit the text on the webpage. The problem is that the resource file is an embedded resource and compiled on ASP.NET MVC Deployment. This means they would have visual studio to change site copy. This is non-optimal :)

Is there a way to make use of resource files in ASP.NET MVC that would result in a .resx file on the server for an admin-type person to be able to edit?

The other option is to put this in a database and have some front end to edit it, but I would really like to avoid this option as its overly complex for just a few text fields on a small site.

Thanks!

Upvotes: 4

Views: 4635

Answers (1)

Christophe Geers
Christophe Geers

Reputation: 8962

Once way of doing so, is to make sure the resources aren't compiled.

When you add a resource file (e.g. TextResource.resx) you can access the resources in a type safe manner.

For example:

ViewBag.Message = Resources.TextResource.MyMessage;

After you add a resource file (*.resx), select it in the solution explorer and view its properties. Clear the "Custom Tool" property. By default it contains the value "GlobalResourceProxyGenerator". Just delete this value.

This has a downside, however as you can no longer access the resources in a type-safe manner. You'll have to load them using the GetGlobalResourceObject and GetLocalResourceObject methods of the current HttpContext.

For example:

ViewBag.Message = this.HttpContext.GetGlobalResourceObject("TextResource", 
                  "Hello", CultureInfo.CurrentUICulture);

This way you'll be able to manually alter the resource files (*.resx). You could then opt to build an application which can read and modify the contents of the resource files, which are just XML files.

For example:

http://www.codeproject.com/KB/cs/Editing_a_ResourceFile.aspx

Upvotes: 5

Related Questions