Asp.Net Mvc 4 Razor Tutorial Pdf
Wwjk9tq7Y/VJAmihbb80I/AAAAAAAAAn0/cOXSZzub6n8/s1600/mvc4.PNG' alt='Asp.Net Mvc 4 Razor Tutorial Pdf' title='Asp.Net Mvc 4 Razor Tutorial Pdf' />Here we will learn complete asp. Setup a multi language website using ASP. NET MVCIntroduction. Since the first release of the. NET framework developers are given the chance to easily configure any kind of project be it a Website, a Web Application, a Windows Forms or XPFXAML client and such in order to support multiple languages. Download ASP. NET MVC and learn how to build web apps using the model view controller pattern. This topic provides links to documentation resources about ASP. NET MVC 5. If you know a great blog post, stackoverflow thread or any other link that would be. Review developer and enduser documentation on DevExpress products online help resources, printable PDF downloads, and more. ASP. NET MVC Tutorial Free Beginner and Advanced Tutorials, Articles, Projects and Source Code for Software Developers, Professionals and Architects. How to build a multilanguage Web Application while adopting the ASP. NET MVC pattern using resource files, Route Mapping and Global Filters. AngularJS. AngularJS is built on the belief that declarative programming should be used to create user interfaces and connect software components, while imperative. This can be achieved using the well known Resource Files. We wont explain them here if youre interested, read the official walkthrough, but well remember a couple key concepts. A Resource Files is basically a keyvalue array of content resources mostly images and text for each supported language. All the developers have to do is to create a . ISO 6. 39 1 two letters language code of the language itself, i. Global. resx file to store text and images for english, assuming itll be our default fallback language. Global. it. resx file to store text and images for italian languagea Global. Once we did that, well only have to write our code using the key specified in these files instead of the actual content if you dont know how, read the walkthrough above ASP. NET will look up the keys in our Resource Files, starting from the one with the Localization closest to the one set for the current thread and then going backwards until it founds something to show. Kickass feature, indeed lets see how we can use it to build our very own multi language MVC ASP. NET Web Application. Resource Files in MVCThe first question would be where do we put the. The answer is all but granted our first choice would be adding the AppGlobal. Resources ASP. NET Folder to our project, just like we always did since. NET Framework 1. 1 where else You could be surprised, but if youre working with MVC this is not the right choice. If you want to know why, you can read the whole story in this great article by K. Scott Allen sul tema. To summarize it, lets just say that the Framework will compile that folder in a separate assembly, thus making them unaccessible to our Controllers, Unit Tests, etc. Resources . Once we added there our. Properties window First thing we need to do is to change the Custom Tool, which is the code generator engine used by the Framework to build the Resource File strongly typed class. The default tool, Res. XFile. Code. Generator, would generate a private class, which is not what we want. Thats why well replace it with the Public. Res. XFile. Code. Generator, which will be able to generate a public class with public methods properties just like what we need. Second settings to change is the Custom Tool Namespace default value, an empty string, means no namespace, which is far from ideal. Thats why well replace it with something like Resources, so the custom tool will generate a code consistent with our folder structure our resources will be located in the. Resources folder and will also have the Resources namespace thats good enough. Notice that these small modifications will be required for each and every . Resource Files so youll always have these settings set, since each . How to serve the proper language to each Request. As we said before,. NET Framework automatically select the Resource Files closest to the localization of the actual thread, which is the one that will process the http request and serve the proper http response accordingly. The localization info are stored in the response threads Culture. Info object, which is usually set against the language specified by the requests browserclient. Meaning that well be able to serve the same contents in different languages depending by the browsers client language settings upon the same URL. Same URL, different content. Would that be a proper behaviour We could be tempted to say yes after all, allowing each user to read the exact same URL in their homenative language seems like a good thing. Problem is, from a SEO perspective its a complete failure. Everyone who knows something about the field knows that you need a different URL for each localized version of the same page. If you have doubts about that, we suggest you to carefully read this brief Google guide about SEO featuring some useful best practices, the most important one being the following Keep the content for each language on separate URLs. This basically means that we cant just set the thread language taking into accont things like the users browser languagecookie values if setuser session values if presentany other Request based field HEADER, POST data, etc. URLBut we need to build a proper URL based localization mechanism, where each language answers to its very own set of URL patterns, such as http www. And so on. Once we do that, were free to use some or all the above info to route the requests we receive to the most suited language i. This basically means that we will use the URL to set the thread localization, and any other info browser language, cookie values and such to choose the users default route. Lets see how we can build our Web Application to make sure it will behave in such way. Set up a Multi Language Route. First thing we have to do is to setup an ASP. NET Route to handle these kind of requests and store the localization related info. If our web application implements the standard ASP. NET MVC route pattern, such as controlleractionid, you can use the following example. Map. Route. name Default. Localized. url langcontrolleractionid. US. defaults new controller Home, action Index, id Url. Parameter. Optional. Map. Route name Default. Localized, url langcontrolleractionid, constraints newlangw2w2 w2, en or en US defaults newcontrollerHome,actionIndex,idUrl. Parameter. Optional. Flash Games In Swf Format Video. Youll need to put this route in the. AppStartRoute. Config. If youre Web Application used a different routing approach, youll need to adopt a similar, yet suitable strategy according to that. The main goal of this localized Route is to isolate and store a. This information, if present, will be used to set the localization of the current Thread so it will use the corresponding Resource Files. Using a Localization. Attribute to handle Multi Language Requests. Now that we have a Localization Route to catch our multi language URL calls and store our language info in a handy variable, we need to find a way to programmatically handle it. To fullfill this task we can create a Localization. Attribute by creating a new Localization. Attribute. cs class the attribute will be executed upon each Action and it will set the current Threads Culture and the UICulture with the value stored into the lang variable by the route. Localization. Attribute Action. Filter. Attribute. Default. Language en. Localization. Attributestring default. Language. Default. Language default. Language. public override void On. Action. ExecutingAction. Executing. Context filter. Context. string lang stringfilter. Context. Route. Data. Valueslang Default. Language. Default. Language. Thread. Current. Thread. Current. Culture. Thread. Current. Thread. Current. UICulture new Culture. Infolang. catch Exception e. Not. Supported. ExceptionString. FormatERROR Invalid language code 0., lang. Localization. Attribute Action. Filter. Attribute privatestringDefault. Languageen public.