Page inside a folder can't find App_LocalResources - c#

I'm using App_LocalResources on my project without problems, that was until i created a aspx page inside a folder, I created the resx file with the same name as i did for others but when the page is inside a folder I cant call the resources for that page.
The way I call resources is:
bt_name.Text = GetLocalResourceObject("bt_name").ToString();
And the soluction struture for the aspx and resx are:
Solution -> Folder -> Page.aspx
Solution -> App_LocalResources -> Page.aspx.resx
What am I doing wrong?

Related

How do I overwrite the default "site.css" that is generated -by something- in dotnet core in the account management mvc section

I have created a scaffolded SPA application where a default UI MVC project was created. I have managed to "scaffold" this where I now have all the .cshtml for account management files locally. I see a "site.css" file loaded from some location somewhere. I want to copy the contents of this file, place it locally -so I can edit it-.
I can simply remove the reference to site.css and add my own *.css reference. But it seems odd that a site.css file is being generated from somewhere and it isn't obvious where it comes from.
The only information I can find on this strange behaviour is:
Where is the site.css file located for Identity?
"you can override those by simply creating files in the same location in your project"
I have tried creating site.css in the "same location"(where is the same location?) but it didn't work. It still loads site.css
[project root]/wwwroot/css/site.css
All public facing files are in the wwwroot folder. So that is where your css, images, javascript, etc. files will go.
Note: "wwwroot" folder is near the top in the Solution Explorer, it doesn't follow the ABC ordering.

ASMX dll not loaded when in subfolder

I am using ASP.NET (3.5) webforms. I have a plugin for a website that contains an .ascx file and an .asmx file. My folder structure looks like this:
MainWebSiteFolder
bin
Plugins
Plugin1
Plugin1.ascx
Plugin1.asmx
bin
Plugin1.dll
At runtime, the main website (using the web.config tag) can find the Plugin1.dll and load the Plugin1.ascx into the webpage. The Plugin1.ascx contains javascript code that calls the Plugin1.asmx, but IIS can't find the Plugin1.asmx codebehind because it's looking for Plugin1.dll in the main website's bin folder instead of the plugin's bin folder.
Trying to reach the asmx directly via URL (http://MyWebSite/Plugins/Plugin1/Plugin1.asmx) results in the following error:
RunTime Error
Could not create type 'MyNamespace.Plugin1'.
Line 1: <%# WebService Language="C#" CodeBehind="Plugin1.asmx.cs" Class="MyNamespace.Plugin1" %>
There are several similar questions out there, but none of them solve my problem because I just own the plugin, so I don't want to copy the plugin.dll into the main website's bin folder (because, when the main website is upgraded, its bin folder is emptied. I don't have control over this). I also don't want to make the asmx its own separate IIS application because it needs to be able to share a session with the main website.
Is there anything I can do to connect the asmx file with its dll inside the subfolder?
Check if adding a web.config to the Plugins or your Plugin1 directory (web.config inheritance), containing an assembly probing-element works (see probing Element on MSDN).

No cs file if MasterPage used

I am currently using Visual Studio 2012 to design aspx pages and have a page which uses a MasterPage which I will call it "a.aspx" for simplicity's sake, and unlike my other pages, "a.aspx" does not have a .cs file attached to it which I assume is because it had a Master Page. Whenever I drag items like buttons into the contentholder of "a.aspx", the code behind page brings me to the aspx page and not the cs page. And I can't import assembly references which I need to because I require some SQL connection in "a.aspx"
So how can I create a webform with a master page while being able to have the contents within my contenthandler to be mqanipulated through a .cs file or can I perform functions in the aspx page too?
You can have all your functions in same aspx file, or you can divide it into two files: aspx and cs. Just enable "place code in separate file" checkbox in "add new item" dialog.
This place code in separate file option depends on the type of project you are building:
1) If you are building a Web Application then (File | New > Project, doesn't have an /App_Code folder, compiles all .cs/.vb files into one .dll in the /bin folder) then you don't have the option to not create a separate code file, and when you add a new item it's either a Web Form or a Web Form using Master Page.
2) If you are building a Web Site (File | New > Web Site, contains an /App_Code folder, the code is not compiled into a .dll in the /bin folder) then you will have the option (ticked by default in VS2008/2010/2012) to Place code in separate file, and also Select master page.

Place Visual Studio resource files in a folder other than 'Resources'?

I have a resource file named rs.resx. In the Visual Studio designer, I can add an image to my resource file by clicking "Add resource" and specifying the path to my image file.
After adding the image, the image file itself is also copied to a folder in my Visual Studio solution named Resources. I would like all of my image files to be placed in a folder named Images instead. Is this possible?
This is a little tricky, but it is possible.
VS checks if the file added to a resource is already defined somewhere within your project. If it can't find it, it creates the folder Resources, puts a copy to the file there, adds this file to the project and puts a reference into the resource designer to this fresh copy of your file.
To avoid this behaviour you should add the file to your project before you add it into the resource file. If the file isn't somewhere within your project structure you can just create a folder, right click it, select Add file and before you click on the Add button of the OpenFileDialog, push on the little arrow next to the button and select Add as link.
Now the file resides on the place on your hdd wherever you like and the resource designer doesn't create a copy within your project file if you now add the file within the resource designer.
Maybe this little picture helps to find the Add as link button:
(source: modbusdriver.com)
That's just a subdirectory of your project directory. Your program doesn't use it at runtime, it should use the embedded resources. Anything you add to the .resx file gets copied there, not just images. But you can rename the folder if you really want to, right-click it and click Rename.
Instead of adding a .resx file to your project, I'd recommend you use the existing one. Project + Properties, Resources tab. Makes it very easy to retrieve the resource at runtime, just use Properties.Resources.Something in your code.

Multilanguage asp.net site with aspx in different levels

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.

Categories