Multilanguage asp.net site with aspx in different levels - c#

I've been working in a multilanguage site build with asp.net and visual c#.
I'm using Local_resources to get my aspx files in Spanish and english.
If a use my aspx in the root of the website the Local_resources folder find the aproppiate resx for my aspx (because both have the same name). But if i put all my aspx into a folder created in the root directory, everything stop working:
as you can see i have a folder named "Inventario" and inside that folder i have Productos.aspx.
In App_LocalResources i have two files, one for spanish and one for english.
If i put Productos.aspx in the root directory they work fine, but i need them like in the image and like that is not working.
What should i do to the resx files to point to Inventario/Productos.aspx ?
Thank you very much.

You have to create a new App_LocalResources folder under Inventario, then copy Productos.aspx.*.resx from <root>\App_LocalResources to Inventario\App_LocalResources, then rebuild your solution.

Related

.NET MVC localized resource file is not read

I was trying to add some satellite resource files to display different language
I followed these two posts in general
stackoverflow post
Localization of a Site in MVC5 Using Resource File
here's what I have done in nutshell (using visual studio 2017, .net framework 4.5)
I created a folder named it "Resources"
I right clicked this folder and created a file named it "Lang.resx", added a string pair (name: Welcome, value: Hello), then switch it to public and save
I right clicked this folder and created another file named it "Lang.es.resx", added a string pair (name: Welcome, value: Hola), then switch it to public and save
I opened up web.config and added following line to System.Web
<globalization enableClientBasedCulture="true" culture="auto" uiCulture="auto" />
I opened up a blank view, write the following to that view
#{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("es");
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("es");
}
<div>#MyProject.Resources.Lang.Welcome</div>
<div>#Thread.CurrentThread.CurrentCulture.DisplayName</div>
<div>#Thread.CurrentThread.CurrentUICulture.DisplayName</div>
The output is as following:
Hello
Spanish
Spanish
As you can see, the culture is changed but somehow the Lang.es.resx is not read, I have created multiple new project in different hosting VPS, the result is always the same.
So there must be something I've done incorrectly, or some steps missing
ok, after a whole day debugging, I've found out the cause
When using resource file, it creates additional folder to the current bin folder, say Language.es.resx, then it creates a folder called es
When I upload the project to the ftp server, this language folder didn't get created and the es recource.dll file was not uploaded
I think this is it, hopefully this can help anyone facing the same problem
In the file properties in Visual Studio, set:
Copy to output directory: Copy always
If you want for multiple files within a folder, you can always edit your .csproj file
<Content Include="parent directory\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>

Website compilation process[AppCode DLLs]

We are working on a website project which contains around 1130 pages. After compilation, all the .aspx.cs files are converted into AppCode DLLs that has random names.
Whenever there are any changes in single .aspx.cs file[like a hotfix], we have to recompile and deploy the entire project on the application host.
We want to update only those files that have been changed and not the entire package.
One of a solution we are aware is that, converting Website to Web application; but we cannot implement that change at this stage of the project.
Is there any other way to find an efficient solution for this?
Yup. Talking in Visual Studio 2010:
While publishing the website, Select the option: 'Use Fixed naming and single page assemblies', Also select 'Allow this precompiled site to be updateable'.
After website is published. Go to the published folder. Open any aspx page (not the dll or .cs).. Note the dll name in page attribute under inherits attribute. Than using ftp or any other way to upload, copy or upload tht dll under bin to your website.
Also, you can create a doc or txt file to list all Dll names with respective paths to your file to easily know which dll to upload next time if there is any change.
Hope it helps.

ASP.NET MVC Global Resource File deployment

In my mvc3 web project I have an App_GlobalResources folder containing the resource file Permissions.resx.
I am able to access the values in this file when I run the site locally in visual studio using:
string value = (string)HttpContext.GetGlobalResourceObject(resourceClass, key);
However, once I deploy it to the production web server it is not able to access the values in this file. I checked and it is creating App_GlobalResources in the bin folder of the publish directory containing the file.
My first time using global resource files, is there any additional steps required to get this working once deployed to the webserver?
Thanks.
I'm pretty sure App_GlobalResources should not be created in the bin folder. Have you got Copy to output folder set? (You shouldn't need it).
In WebForms, in properties of the .resx files, we have Build Action set to Content and Custom Tool set to GlobalResourceProxyGenerator. This creates dlls for the resources in the bin folder.
However, I've not used App_GlobalResources in MVC (it makes things tricky to test outside of a web context), but there's some info here that might be useful:
http://odetocode.com/Blogs/scott/archive/2009/07/16/resource-files-and-asp-net-mvc-projects.aspx

asp.net App_LocalResources folder

I would like to have App_LocalResources folder outside web application folder, so that I could deploy updated resx files and web app. independent of each other.
Reasons: We do not want to change current deploy tool.
Any way to achieve this?
Way the default resource manager works in asp.net is it picks the resex entries for the respective aspx file from the App_LocalResources folder in the current directory. As far as I know this behavior is not something you can configure (i.e to ask it to pick entries from a different folder!) But there is a workaround, that you could implement your own Resource Manager and let it picks entries from a location you specify it to. Found this and this while googling. Hope that helps.

Does an assembly maintain its directory structure?

Since all files in a web project are compiled into single assembly, then does this assembly maintain a directory structure? For example, if a file in a root directory references a file in a subdirectory, then how could this reference still be valid when the two files get compiled into same assembly?
Assume a web project has the directory structure shown below.
Since all of web project’s ASPX files get compiled into a single assembly WebProject1.dll, how is this assembly able to record/memorize the directory structure?
Thus, when you deploy WebProject1.dll to a web server and user makes a request for http://WebProject1/some_SubDir/default.aspx, how will WebProject1.dll be able to figure out which Page to render?
WebProject1\SubDir (where WebProject1 is a root directory)
WebProject1 -- contains several ASPX files
WebProject1\SubDir -- contains a file default1.aspx.
When we deploy the Web project, must we create the same directory structure on a web server (WebProject1\SubDir), even though we won’t put any ASPX files into those directories?
I assume that on Web server WebProject1.dll should be placed into the Bin directory?
thanx
EDIT:
Only the sourcecode is compiled into the assembly, you still need to upload the aspx files into a matching directory on the server.
My book says that when using Web project all web code is compiled into single assembly. I thought “all code” includes aspx files?!
Links are maintained between the page and it's code behind file through a class declaration which by default is in a namespace that matches the directory structure
So if I add a new aspx page via Project --> Add New Item, and store this aspx page in a subdirectory named Hey, then this page will reside in namespace WebProject1.Hey?!
But how do I do add new item into a subdirectory, since Project --> Add New Item doesn’t give me an option to browse and choose a directory I wish to save it in, but instead automatically creates aspx file in a root directory?
The relative path is kept when the compiler generate the dll.
I’m not sure I know what relative path you’re referring to?
thanx
Only the sourcecode is compiled into the assembly, you still need to upload the aspx files into a matching directory on the server. For example you project in Visual Studio may look like the following:
WebProject1 (The root project)
|
|- some_SubDir (A physical directory inside the project)
|
|-default1.aspx
|-default1.aspx.cs (assuming a C# project)
Once you have compiled the web app you'll need to upload the following to the server:
WebProject1 (The root directory for your website)
|
|-bin (The binary directory created by the build)
|
|-WebProject1.dll (The compiled source code of the web app)
|-some_SubDir
|
|-default1.aspx (The file that will map to the URL www.websitename.com/some_subdir/default1.aspx)
Compiled resources (non-sourcecode files that are compiled and stored inside the assembly) are different issue that are addressed in your other question
Edited to add direct answers to the questions:
Not all files are compiled into the assembly, only source code files are. Links are maintained between the page and it's code behind file through a class declaration which by default is in a namespace that matches the directory structure, but it doesn't have to be.
Your default1.aspx file will have in the header something like:
The inherits line tells the webserver that when a user requests this page it should be processed in conjunction with the source code that defines that class, which it will find inside the compiled assembly. The combination of the physical aspx file and the compiled class will generate standard html which is then passed back to the client.
Yes, you need to create the same directory structure, but you are required to put the aspx files in there.
Yes
(can someone please edit this if they know how to get the list items to number correctly, please?)
All those path information will be embedded as Meta Data/resource file, so, you can deploy it safely to the server. The relative path is kept when the compiler generate the dll.
I suggest you use Reflector to open the dll, and you can get a much more deeper understanding what is inside dll.
Notice how some_Subdir/default1.apsx has a 'Inherits' key/value pair in the page declaration?
What this means is that when you make a request for that resource IIS goes 'Ah ha! Asp.Net needs to handle this request! Hey asp.net please return me some html to send down'
Asp.net parses that aspx file and creates a proxy class on the fly that inherits from WebProject1.some_Subdir._Default1. This proxy class then parses out the control tree and html, and kicks off the page life cycle (this is overly simplified, and I'm sure I've missed some details).
So the WebProject1.dll is just the actual C# / VB of your web app, but in concert with the asp.net worker process and the markup you can render html back to a client.

Categories