4

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!

2
  • Does it HAVE to be an embedded resource? Commented Aug 11, 2011 at 15:31
  • If I remove it as an embedded resource the page that uses the resource fails. I don't really understand resources, so I'm not sure how to make it work in a non-embedded way -- hence this question. Commented Aug 11, 2011 at 16:14

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

2 Comments

I down voted because it's not a solution to the original question but an alternate way that may require changes in the whole application.
@AridaneÁlamo: I don't agree with your downvote. The answer is exactly what the poster is asking for. To be able to edit *.resx files which are deployed on the server. The only way to do this is to make sure they aren't compiled. Loosing the type safety goes hand in hand with that. It's not like there's a way around it. In a comment to the question the poster clearly states he did not know how to use them in a non-embedded way, which is what I explained.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.