ASP.NET: Best way to manage global resources? - asp.net

I've a couple of email templates and I would like to store each in a sepparate file. I'd like to avoid having to read them from disc everytime I need them. Is there any built in structure in ASP.NET that automatically loads them when needed and shares this resources throughout the application?

You can store the email in the Application Dictionary or in the cache or in resource files but in the long run I have found that depending on the size of the file, the amount of files and the frequency of use it is often best to just read it from the disk every time. This way you do not clog memory and you do not have to have any caching code.
If the file is small and you only need it every now and then just read it from the disk. If you only have a few templates and you need them all the time then go with one of the other suggestions. (if the templates are plain text I would use the resource files and not reinvent the wheel, but if you need complex templates you may want something else)

You can use the Cache or Application objects.
Also, for simple tasks, a simple static field would suffice.

You can create a Global_Resources folder in your web app and put global resources files there. (*.resx files)

ASP.NET Caching is good for your problem.
Also you can use Enterprise Library Caching Block.

System.Web.HttpApplicationState

Related

What is the best architecture for file management website?

Here is what I think my website should be able to provide to user.
Ability to upload file to the system. It should not blocking, user should be able to surf other pages of the website while upload is ongoing. Once upload is done user will get notified about upload.
User should be able to view of his/her uploaded files in website.
Ability to edit files in web browsers using third party APIs
Number of user are going to be around 5000, and all of them might upload files at the same time so performance should not decrease.
Where should I store this files? How to make sure that read and write of files on this directory should handle concurrent user request?
Considering above points. What should be the best way to architect this website?
Are there any existing web framework that play along with this type of architecture like rails, express?
If you want to have the ability to browse the site while a file is uploading, you'll want to use something on the front end that overrides anchor tags and asynchronously fetches the next page - there might be a library or something to accomplish this but it should be easy to implement yourself with jQuery.
To make this easier (and for many other reasons), you'll almost definitely want to structure your site with an MVC (Model View Controller) architecture. Rails is structured this way, as is almost any web framework. It doesn't sound like what you're describing is better suited to Rails over PHP or Python etc so just use whatever language or framework you (or your developers) feel most comfortable with. You might want to do some research into available plugins for editing files (it really depends on what type of files you want to edit and how) and using those to influence your decision on which language to choose as well.
With regards to storing files on your server, any logical system should suffice. Perhaps:
/username/year/month/day/myFile.txt
You'll want to do something to ensure filenames don't clash as well. And obviously you'd want a database storing the information linking files to users.

Where is the best and easiest place to store global website settings

I'm just putting together an internal data system for a client, which is ASP.NET VB, backed by an SQL database, on an in-house IIS7.5 dedicated server.
I want to store certain global settings, such as the age limit for news articles, admin contacts etc, in a file NOT within the database (i.e. to avoid unnecessary database query's)
Where would the best place to store this be? global.asax? app.config? or a custom XML file? how would i import these at runtime? (probably to session variables)
ETA:
Also - the settings must be editable from within the site, i.e. an admin section i'm yet to build
If you need these settings to be editable, then the simplest place to store them would be in a database table. You're already building a layer to get in and out with CRUD operations, so adding this little extra won't hamper you. This will also help you keep your web.config clean and your supporting libraries will not need an extra app.config built into them.
Resource files and embedded app.config files are not editable so those preferred methods don't meet your requirements. You don't want people accessing the web.config directly (even through an interface) because changes to the web.config cause the application pool to recycle. A custom XML file would work, but you would have to build a separate parsing engine to get in and out of it. While this is simple, it would be unnecessary since you're already building an access interface for the rest of your database.
If you're really hating yourself though, you could combine the two into a custom xml file stored in the database as an XElement.
Thanks for your suggestions.
I decided the easiest method, given that the details may only need altering a couple of times a year, was to set session variables in global.asax

ASP.NET modify resource values from .resx files at runtime

My current requirements for the application that I am working on are that the client should be able to modify the texts used in the interface from a screen within the application itself.
These are of course saved in resx files.
Is there any way to do this?
Modify the values of the resources at runtime?
What would be the easiest way?
Thank you in advance
Edit: resx files are already implemented and there are a lot of keys used all throughout the application
If the requirement is to edit label texts during runtime than I would suggest that you don't use RESX files, as them are ment to be static, but rather use database.
You could write your own provider using a database as backend. This way your code doesn't change and you'll have the possibility to update text directly.

Using SQL for localization instead of RESX files in ASP.NET

I'm thinking of developing the following but wondering if it already exists out there:
I need a SQL based solution for assigning and managing localization text values for an asp.net site instead of using RESX files. This helps maintain text on the site without having to take it down for deployment whenever an update is required.
Thanks.
We actually went down that path, and ended up with a really really slow web site - ripping out the SQL-based translation mechanism and using the ASP.NET resources gave us a significant performance boost. So I can't really recommend you do that same thing.... (and yes - we were caching and optimizing for throughput and everything - and the SQL based stuff was still significantly slower).
You get what you pay for - the SQL based approach was more flexible in terms of being able to "translate" on the fly, and fix typos and stuff. But in the end, in our app (Webforms, .NET 2.0 at that time), using resources proved to be the only viable way to go.
We did this (SQL-Based Translation) and we are really happy with the result! We developed an interface for translation-agencies to perform the updates to the page online. As a side effect, the solution started to serve as content-management system. If you cache your data, performance is not an issue. The downside is, that we invested multiple hundreds of hours into our solution. (I would guess sth. arround 600 hours, but I could check.).
We ended up with a hybrid solution where users could edit content into a database but the application then created a .resx which was deployed manually.
You could also bypass the server translation altogether and do translation in jQuery on the client which is an approach I have used successfully.
I'm not sure about the website restart, but at least using .NET MVC is very convenient and I haven't noticed that restart problem, and, if occurs, how often you need to update the resx files? For bigger projects I use to create a solution with multiple projects, one for the localization, something like this:
MyApp.Localization
Model
Page
File1.resx
MyApp.Core
MyApp.Web
Then in the Web project I add a reference to the Localization project, and use it like
#MyApp.Localization.Model.Customer.CustomerName
#MyApp.Localization.Page.About.PageTitle
#MyApp.Localization.File1.Paragraph1
Everytime I change the translated text, I either upload an updated .dll or copy the .resx files.
NOTE: You need to set your resx files to PUBLIC, so can be accessed as strongly typed.
I created a SQL based translation scheme. But I only load the needed translations for a given page when it is requested, and just the ones for that particular page.
Those get loaded into a dictionary object when the page reloads and cached during the session. Then is just does text replacement based off a lookup on that.
Pretty much all of it is dynamically generated, and includes user defined content that must be translated, so the flexibility is key.
Performance is quite fast, the SQL queries to retrieve all the data take much longer (relatively speaking).

ASP.NET XML ObjectDataSource Wrapper Class Examples

I want to use XML instead of SQLServer for a simple website.
Are their any good tutorials, code examples, and/or tools available to make a (prefer VB.NET) wrapper class to handle the basic list, insert, edit, and delete (CRUD) code?
The closest one I found was on a Telerik Trainer video/code for their Scheduler component where they used XML to handle the scheduling data in the demo. They created an ObjectDataSource class. Here is a LINK to that demo if anyone is interested.
[Reply to Esteban]
it would make deployment easier for clients that use godaddy where the database isn't in the app_data folder. also backing up those websites would be as simple as FTP the entire thing.
i have concerns about possible collisions on saving. especially if I add something as simple as a click counter to say a list of mp3 files visitors to the site can access.
In these days of SQL Server Express, I'd say there's really no reason for you not to use a database.
I know this doesn't really answer your question, but I'd hate to see you roll out code that will be a nightmare to maintain and scale.
Maybe you could tell us why you want to use XML files instead of a proper database.
It would make deployment easier for clients that use go-daddy where the database isn't in the app_data folder. also backing up those websites would be as simple as FTP the entire thing.
I have concerns about possible collisions on saving. especially if I add something as simple as a click counter to say a list of mp3 files visitors to the site can access.

Resources