IgnoreRoute with file extension is not working in MVC - asp.net-mvc

I have a Content folder and i want all the html files inside the Content folder from getting accessed, so i added this line at the top of the RegisterRoutes() method in the RouteConfig.cs file as follows
routes.IgnoreRoute("{folder}/{resource}.html");
but still i am able to access the file.
I even tried giving a static value like this
routes.IgnoreRoute("Content/{resource}.html");
and like this
routes.IgnoreRoute("Content/demo.html");
but still was able to access the file, am i missing some thing, how can i acheive this behaviour.

Related

Blazor Server localization

I have a project using Localization. program.cs:
builder.Services.AddLocalization();
...
app.UseRequestLocalization(new RequestLocalizationOptions()
.SetDefaultCulture(LanguageList.GetSupportedLanguages[0])
.AddSupportedCultures(LanguageList.GetSupportedLanguages)
.AddSupportedUICultures(LanguageList.GetSupportedLanguages));
Where LanguageList.GetSupportedLanguages is nothing but an array of CultureInfo.
It's working perfectly; however, I have put the .resx files in the same folder as the razor files and the folder content gets quite messy fast. If I move them, it doesn't work anymore.
I read in Microsoft doc that the Resource file path can be set by:
builder.Services.AddLocalization(config => config.ResourcesPath = "Resources");
However, if I move the resx files to this folder two things happen. It doesn't work (text is not set) and I get this error message:
Custom tool PublicResXFileCodeGenerator failed to produce an output for input file 'Resources\Index.en.resx' but did not log a specific error.
I been trying some tips I found here on StackOverflow, among them adjusting the folder structure to mimic the namespace.
No luck. What am I doing wrong here? How do I utilize the ResourcesPath setting?

How can I reference a script that is in my pages directory?

I'm trying to keep a good practice of keeping context together and in that regard, I like how Razor Pages forces you to place your view models next to its view. I'd like to do this with script files as well.
For example, if script is a bit large and is only used on this particular page, it may not be the cleanest thing to have it in a render section in the cshtml. Instead, I'd want to place it into its own .js file. But to keep the project easy to navigate for team members, I'd like to place that .js file in the same folder next to its view and view model. I'm not sure how to link that file, or if I even can. If I give src a path to the file, it is not found. Assuming that's because wwwroot is the only folder setup to host static files.
Suggestions?
You can add an option to the StaticFilesProvider in your Configure method:
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(),"Pages")), RequestPath="/Pages"
});
See the documentation on Static Files in ASP.NET Core: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-2.1

Cannot find my View

All my Views are defined in a folder called "site_admin". But when I browse like this http://localhost:1234/site_admin/home/index. It gives me the following error
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /site_admin/home/index
It looks like its having problem finding the location of my View. All my views should be inside the "site_admin" folder and should be accessible from there.
Any help would be greatly appreciated.
Here is how routing works in MVC. Default routing means you have a controller, like UserController and in that file there is a method, say NewUser(...). Then you also need a view folder named User and inside that a NewUser.cshtml file. Now, if you to to mysite.com/User/NewUser that will first hit the User controller and look for the NewUser method. Once that code is run it will look for the NewUser.cshtml file in the Views/User folder.
There are several way of overriding this default routing (routeconfig.cs, route attributes, etc) but that is the basics of how it all ties together.

Generate URL of resources that are handled by Grails AssetPipeline

I need to access a local JSON file. Since Grails 2.4 implements the AssetPipeline plugin by default, I saved my local JSON file at:
/grails-app/assets/javascript/vendor/me/json/local.json
Now what I need is to generate a URL to this JSON file, to be used as a function parameter on my JavaScript's $.getJSON() . I've tried using:
var URL.local = ""${ raw(asset.assetPath(src: "local.json")) }";
but it generates an invalid link:
console.log(URL.local);
// prints /project/assets/local.json
// instead of /project/assets/vendor/me/json/local.json
I also encountered the same scenario with images that are handled by AssetPipeline1.9.9— that are supposed to be inserted dynamically on the page. How can I generate the URL pointing this resource? I know, I can always provide a static String for the URL, but it seems there would be a more proper solution.
EDIT
I was asked if I could move the local JSON file directly under the assets/javascript root directory instead of placing it under a subdirectory to for an easier solution. I prefer not to, for organization purposes.
Have you tried asset.assetPath(src: "/me/json/local.json")
The assets plugin looks in all of the immediate children of assets/. Your local.json file would need to be placed in /project/assets/foo/ for your current code to pick it up.
Check out the relevant documentation here which contains an example.
The first level deep within the assets folder is simply used for organization purposes and can contain folders of any name you wish. File types also don't need to be in any specific folder. These folders are omitted from the URL mappings and relative path calculations.

overriding front template translations doesn't work

I'm working on prestashop and I'm Trying to override "order detail page" in front (customer's details orders).
This is how I did :
I copied file \controllers\front\OrderDetailController.php into folder \override\controllers\front\OrderDetailController.php
I copied also default template file order-detail.tpl into folder override/customtemplate/order-detail.tpl
And In OrderDetailController.php I have specified template directory like that
$this->setTemplate(_PS_OVERRIDE_DIR_ . '/themes/parfum_evo/order-detail.tpl');
I tried, it works fine except translations. Even watching the documentation, no test solution seems to work.
Could anyone help me? Thank you in advance :'(
The php override sits in the correct place. As for the other, you specified the path the override/customtemplate/order-detail.tpl but then placed it in override/themes/parfum_evo/order-detail.tpl. I take it as customtemplate is farfum_evo really, but you need to add another one named themes, after override, using that structure. I think. Because there is a hook named
DisplayOverrideTemplate
Which should take care of this, while I believe setTemplate for controllers will always grab from the main theme folder

Resources