How to impliment dynamic localization asp net - c#

I am trying to come up with the best way to localize an asp net mvc website dynamicly. As in the administrator of the website should be able to change any string, in any language, at any time without recompiling. I was beginning to think that using SQL would be a good idea, but that would seriously take a hit at performance.
My other idea was to store localization in xml files, but then read from them as needed. However, I dont remotely know where to begin. I have seen some guides on how to do this with resource files, but those are compiled and not editable on the fly.

I think this post may be useful for you

Although I've not used it personally take a look at this by Rick Strahl (A Microsoft MVP) http://www.west-wind.com/weblog/posts/2009/Apr/01/Updated-WestwindGlobalization-Data-Driven-Resource-Provider-for-ASPNET it may be a good fit for what you require.
It is available on NuGet here http://nuget.org/packages/Westwind.Globalization .
Also worth noting is this page covering support for MVC http://www.west-wind.com/westwindwebtoolkit/Docs/index.htm?page=_2r1166lmq.htm

Related

Is IStringLocalizer meant just for ASP.NET?

I stumbled across the entire Microsoft Localization Extensions section the other day. IStringLocalizer/ILocalizedString, all that.
I've already got a hand-rolled approach to localization in my current app (.NET 6, WPF, Prism), but I would gladly convert over to this if appropriate; Because it's much easier for a new developer coming on a project to understand something when there are reams of standard MS documentation about it rather than trying to guess what I had in mind.
But virtually every discussion or example of IStringLocalizer that I can find seems to relates to ASP.NET or at least web apps. The docs all seem to assume you're writing ASP.NET.
So are these extensions meant just for ASP.NET and web apps? Is anyone using this approach outside of web apps? And if so can anyone point me to any examples?
-Joe
No, as by docs (2021):
In this article, you will learn how to use the IStringLocalizer and IStringLocalizerFactory implementations. All of the example source code in this article relies on the Microsoft.Extensions.Localization and Microsoft.Extensions.Hosting NuGet packages. For more information on hosting, see .NET Generic Host.
There is no mention of being asp.net specific, although, asp.net applications obviously tend to make use of it as well.
The examples do not use asp.net.
I've used the resx file approach in the early days a lot in WPF applications - although slightly different, I see no reason why it wouldn't work in any regular application.

Confusion moving to ASP.Net from Classic ASP

Probably sounds a bit stupid but I'm getting confused moving from Classic ASP to ASP.net.
After looking at the two different variants of the language, VB or C#, I have decided to go with C#. I was reading another StackOverflow answer that explained moving from VBScript to C# was easier to learn coming from VBScript.
So, I thought I'd hit W3schools to learn some basics on C# but got confused when I was given the options; Web Pages, MVC or Web Forms. Would somebody please explain the differences and which one would suit me best?
I have been coding in classic ASP/VBScript for many years, building all kinds of web application, some big, some small, and I do not want to use any software like Visual Studio, I just want to write code. I currently use Dreamweaver just for coding.
For a move from classic ASP to a .NET web platform, I would suggest going with ASP.NET/MVC.
WebForms are an abstraction that was created to make VB6 programmers comfortable with working on the web and it is a very leaky abstraction. It uses an event model and an idea of PostBacks that simply is not part of how the web really works. It has limitations that will not be familiar or make much sense at first (you can only have one form on a page, for example). As such MVC will be much more familiar.
I suggest that you watch this video by asp.net official developers as well as other relevant videos at the migrating section
Here's another good video produced to help programmers to choose the programming model (webforms, webpages or mvc, tools, etc)
Although w3schools has several good examples, it has several inconsistencies as well as incorrect information. Good alternatives for w3schools include MDN and IE Reference API (as the name implies, it's aimed to IE, and it's a good reference for when something works in other browsers but not in IE)

ASP.NET/MVC 3 Status

What is the status of ASP.NET/MVC technology? Would there be big changes that affect every code base? Is it stable (backward compatible) enough to be used in real world?
Best Regards
You know, the very site you're using.. Stack Overflow, was written in MVC. That should answer your question.
Yes, it is stable. Yes, it is production ready. It is used on this very same site. Depending on your existing code base there might or might not be big changes in order to port it to ASP.NET MVC 3.
Kaveh, I banned using MVC1 in my team because I am a late adopter but a fast adopter (agency work doesn't have time for discovering bugs on behalf of the creator).
Since MVC2 (and now including MVC3), I am very very keen for people to use it. There are some things about MVC that might be difficult if you've only ever worked in web forms, but if you understand http, and html, then it has cut away a lot of the annoying bulk in web forms.
MVC will quickly overtake Webforms in popularity.
MVC
requires less code in most cases.
MVC enables very easy integration
with other client side frameworks and now defaults to using jquery as a standard (in webforms, lightweight ajax usually requried a lot of custom code and quite a bit of repetition).
MVC generates almost no
garbage in your html output.
MVC is
long overdue, stable, secure and simply a
fantastic step in the right direction
for Microsoft.
I would only suggest you tread carefully with where you get your advice on how to do things and any use of 3rd party products like StructureMap that are not supported by Microsoft. I have seen some people make big mistakes with that combination, but never because of MVC.
There was little or no breaking changes from MVC2 - MVC3 unless you'd used certain approaches. I would actually say you are less likely to get breaking changes in future but any version upgrade in any platform will require some work if the changes are worth it.

Are there alternatives to ASP.NET for C# web development?

Lately, I've been thinking that I'd like to try some new ideas and a new approach to web application design. I'm mostly used to using ASP.NET (.NET 2.0) but I've toyed with the ASP.NET MVC library a little bit as well. While both are powerful and interesting, I'd really like something more... basic.
Is there anything like that out there? I'd like a framework that's more transparent really: I want to be able to see the request, pass it where I want, render HTML the way I want, and post requests how I want. I can get all that in ASP.NET, but I have to dig pretty hard to get at all of it. I'd like something simpler to use as the basis for some new framework ideas.
So is there something like that out there? Or would I pretty much have to completely reinvent all the basic routing, request, and response code as well to get a platform to build up from?
I'm not sure if it fits your requirements, but you could definitely check out Manos
It's not answering the question but I really strongly think you're making a mistake here.
MVC lets you deal with rendering in the way you want (it's not like the bad old webforms), HttpHandlers let you deal with Requests and Responses as low down as makes reasonable sense (to me). 99 times out of 100 you don't want to have to deal with the raw raw data coming from the web server (and what is raw anyway? "Request" is an abstraction itself...).
I think you have to look long and hard at your motivation and consider the practical costs if you could get there.
You should look at Fubu MVC then FubuMVC
I would say if you are set on C# as your language ASP.net MVC is as good as it gets right now. You may want to experiment with other template engines like Spark or Nhamle.
I would go and implement an HTTP handler using ASHX files. It gives all the power of ASP.NET object model but do not limit you on any special way of handling the request.
If you are looking for alternate frameworks you might want to have a look at Nina
https://github.com/jondot/nina
From the website:
Nina is a web microframework for the .Net platform, inspired by Sinatra. It includes several aspects that go futher beyond Sinatra, such as an abstract, pluggable, and extensible infrastructure.
A simple to use DSL, a simple programming model.
Performance as a goal.
Multiple pluggable view engines.
Many scenarios covered by Json and XML serialization support.
Advanced cache-control for a RESTful ecosystem; automatic ETagging and Last-Modified controls.
Nina is intentionally build against the .Net 2.0 runtime in order to afford a lower barrier of entry!. A port of Nina for the 4.0 runtime will be available shortly.
Razor support note: I chose to use RazorEngine, which is an open-source abstraction of a Razor view engine without using the full MVC stack. In that implementation, view data is exposed as 'Model'. I chose to align other views and now each view has its view data accessible by 'Model' and 'ViewData' members (except Razor).
I think you want the WebMatrix.
It's basicly a very simple (ASP like) model, but then coded with C# / .Net, and you get the #Razor syntax.
Although this is a relatively old question, I would like to add some other frameworks that are worth a look:
MonoRail is older than Asp.NET MVC and very similar to it. They are currently working on Version 3 of MonoRail. I used MonoRail Version 2 for a side project and it was a nice experience.
OpenRasta. I have no experience with this right now.
TinyWeb. An excellent Asp.NET Micro Framework (You may find the comparison of .NET Microframeworks interesting (including the Anna and Jessica web frameworks))
There is the ASP.net Model View Presenter which may be something like what you are looking for.
http://www.codeproject.com/KB/architecture/ModelViewPresenter.aspx
It sounds to me like you're looking for a microframework like Sinatra , but in c# instead of Ruby. I am not aware of any such framework.
I recommend you dive into Sinatra itself. Learning Ruby will help expand you as a developer, you'll be closer to the HTTP metal (which sounds like what you want), and it'll be fun. The minimalism and simplicity that it sounds like you're looking for is much more popular in the Ruby community.
If you can use mono. Then you can try Mongrel2 with dot net bindings. It is very fast language agnostic web server. It works via zeroMQ.

Lightweight .NET web development?

I'm currently working on a project that has a sizable amount of both client and web code. The client code is written in C# and the web piece is written in PHP. Maintaining consistency between the two worlds is becoming cumbersome, and I want to consolidate the web code to .Net.
The issue is that I hate web development in ASP.Net Web Forms. I want something as raw as PHP, just using C# instead. I've read a little about ASP.Net MVC, but it looks like it abstracts too much of the request logic for my liking.
Does anyone know of a lightweight way to allow C# + .Net to handle web requests? Should I be looking more closely at MVC?
Update: I went with ASP.Net MVC and I've been very pleased so far.
If you're looking to get away from ASP.NET Web Forms, the I recommend ASP.NET MVC with a custom view engine (like Spark, or NHaml). This will give you the consolidation your looking for and allow you to avoid most of the Web Forms that your not happy with.
AFAIK, to do .NET web development, you are going to have to interact with ASP.NET in some form or another, but the custom view engines in MVC could be exactly the abstraction your looking for.
It is now possible to use a software stack completely separate to IIS and ASP.Net using Kyak, Nancy and Gate.
http://bvanderveen.com/a/gate-0.1.0/
You might want to check out Kayak, which is, to my knowledge, the only standalone .NET web development framework that's not ASP.NET.
Caveat: Kayak's request handling implementation is not the best, so there may be performance or scaling issues. I can't say for sure -- I've only read it, not run it.
Edit: I've taken another look at the source code, and it looks like they've rewritten a significant portion of their server code, and in doing so fixed the major issues. Performance probably won't be a problem.
MVC.NET is open source, so you can make it do what you want. It is a framework that is overrideable, extensible, etc. I'd look closer at it. It works great for me and I've come from a background of CGI, Struts and Webwork. I love it.
In my opinion nothing is more lightweight than the combination of NancyFX (http://nancyfx.org/) with Dapper (https://github.com/SamSaffron/dapper-dot-net) for data access.
NancyFX can be hosted within ASP.NET, WCF, Azure, OWIN-compatible environments, Umbraco or you can write your own host.
Read also these articles:
http://theothersideofcode.com/lightweight-development-in-dot-net-nancy
http://theothersideofcode.com/lightweight-data-access-in-dot-net-massive
I also suggest you to TinyIoC (https://github.com/grumpydev/TinyIoC) for decouple your application layers.
Regards,
Giacomo
You should look into the IHttpHandler and IHttpModule interfaces. These are the foundations for ASP.NET WebForms. Brad Wilson has a good intro to the former.
In the bad days when WebForms was the way to do ASP.NET development I was writing my own simple MVC framework with these interfaces. The bit I struggled with at the time was the View engine but now there are a number of these.
You take a closer look at ASP.NET MVC since the source is available and decide for yourself. It may be that you want to change some of the conventions used rather than the whole framework.

Categories