Load Javascript just for admin in silverstripe 3.1 - silverstripe

Im trying to add some custom javascript to my admin but not having such a good time. What I tried so far is.
Requirements::javascript('../mysite/modules/widgets/widgets/calculator/admin/js/admin.js');
The path is correct because when I do fopen to that it returns true.
I have also tried the following.
LeftAndMain::require_javascript('../mysite/modules/widgets/widgets/calculator/admin/js/admin.js');
Same thing with fopen.
It doesn't give any error niether is it loaded(I checked network tab in dev tools)

The path should be relative to the site root not the cms or framework folders. In other words: 'mysite/modules/widgets/widgets/calculator/admin/js/admin.js'
Depending on your situation, I've had more luck using yml for this. I'm not convinced the dynamic loading always works perfectly on ajax requests. In this case it would look like:
LeftAndMain:
extra_requirements_javascript:
- mysite/modules/widgets/widgets/calculator/admin/js/admin.js

Related

API setup missing something?

I am setting up a web api for the first time and I have another project for reference. It is a .NET framework project that will have a React frontend. I am running it using Visual Studio and IIS Express.
I have no build errors when I start the api project. It has swagger added so I can test database calls, so I know the api itself is working. But I am missing adding something as I am looking to add more security to it.
I am trying to verify authentication and I want to use integrated Windows authentication. When I set a break point, the user in the HttpContext.Current is never set and is never authenticated, so I can't add any authorization filters.
I went back to just the basic empty api project that has the frontend web pages removed to see if I removed something and it shows the same issue. So I either removed it again or I am actually missing adding something.
I am not sure where to look for what is missing, so any pointers would be appreciated.
The left browser is what I am expecting and the right browser is what I am seeing.
I don't need the directory browse turned on, so seeing a 403.14 - Forbidden is fine. But I am clearly missing something to get to that point. Is there a better way to figure out which resource/dependency is causing this error?
I can also see the working version requested url is what I am expecting, but the other is just a /.
Is there a way to resolve that if this is the error?
I can add code snippets if needed, but I haven't yet as I am not sure where the issue is.
I ended up finding the answer using blank test web apis to see what I may have left in that wasn't needed. The project was set up using this option:
After removing the views, etc., to make it strictly an api project. I started removing references (and clearing the associated errors) and seeing what happened with the build after each change.
Under the App_Start folder, there were some additional files that weren't present in the project I had for comparison - FilterConfig, and RouteConfig - which were also called in the Global.asax.
I removed the call in Global.asax for all three and I was able to see the expected http error page.
I dont have enough reputation for a comment, but you got 404 error, which, as you know, means there is nothing on that url. So check the route config and startup.cs Edit: I am on the phone so I didnt saw you already solved it. Good :)

401 unauthorized error access CSS files MVC

First things first, yes I am fully aware this has been addressed here before, however none of the solutions seem to resolve my issue. My problem is simply that I have created a new web project and everything works fine with the default code template that VS2013 has provided, the problem I am currently runing into is adding my own CSS files. This is the process I went through to add them:
added CSS folder under the already existing Content directory
Linked to CSS files in the header CSHTML (I can be sure it is linked properly as it is not a 404 error
but when i run the project i get: Status Code:401 Unauthorized (pulled form the network explorer in chrome dev tools), nothing more. I have tried everything from modifying my config file to setting WindowsAuthentication to true and even moving NTLM to the top, to going into IIS and giving everyone access to every possible function to the CSS directory, been at this for an hour and I'm simply lost, any ideas?
Edit: if it helps at all this is the erro i get when i navigate to one of the CSS files:
I found the issue and I feel incredibly stupid about it, as it turns out all of my css files had encryption set on, i simply had to turn it off: right-click
*.css file > Properties (General tab) > Advanced button > Encrypt contents to secure data checkbox.
Works like a dream. If anyone ever purchases a template form ThemeForest, be wary of that.

What is a "weak route" in Symfony 2?

When using the Symfony2 plugin for PHPStorm, I sometimes see a Weak Route warning:
What does it mean?
Worked it out. The Symfony2 plugin parses the appDevDebugProjectContainer.php file to get route and service information. However this file is only recompiled when the web page is loaded which means newly created routes are not included.
To get around this the plugin also parses the config files but this is not 100% reliable so routes discovered in this way are marked as "weak". Reloading the web page will make the warning go away.
I finally fixed this issue for my situation (Symfony 2.8 / PhpStorm 2016.3).
It's similar to #Atmarama 's solution but I think my version of PhpStorm (2016.3) is different and/or Symfony 2.8.
My solution also doesn't involve the deprecated setting. I hope this will help others:
In PhpStorm go to Languages & Frameworks > PHP > Symfony > Routing and add the path to appDevProjectContainerUrlGenerator.php.
In my case this is:
var/cache/dev/appDevDebugProjectContainerUrlGenerator.php
Check path to file urlGenerator
For me right path is:
var/cache/dev/appDevDebugProjectContainerUrlGenerator.php
And after make click to button "Clear Index" above
I also get the same problem and in my case, because i use '/' to declare the render template instead of ":"
Changing from "/" to ":" cleared that warning in my case

Orchard CMS- Configure Base URL

I installed the latest version of Orchard on my dev machine using a base url of localhost/frankgiotto. Then I moved the site to www.frankgiotto.com and updated my Base URL in the settings.
Site works perfectly. I love everything about it but the one thing is that all the links on every page are mapping to www.frankgiotto.com/frankgiotto/etc and I want simply www.frankgiotto.com/etc
This is driving me insane at the moment.. help anyone!?
p.s.. Yes, I made absolutely sure that Base Url is set to www.frankgiotto.com
Interestingly enough, www.frankgiotto.com/Blog and www.frankgiotto.com/frankgiotto/Blog both work and take me to the same place. Its the same with everything else on the site.
This is little out of context, but to make the orchard urls work without any issue on local just do the following
go to Web project
open property->Web
check for "virtual path", set it empty, and all will be fine
that will make the app run without "/", hence less chance for the above issue
Yes, that is a known issue unfortunately. This is because for now links and image addresses are just stored as plain HTML in the database. Ideally, they would be stored as logical references instead and could be rebased on the production server. This feature does not exist today so what we encourage people to do is to use a port rather than a virtual directory on their dev box if they are going to deploy at the root of a domain. This way relative urls just work. In your case I'm afraid you'll have to manually rebase the existing links and change your dev box configuration.

ASP.Net error: "Cannot use a leading .. to exit above the top directory"

I'm seeing this error several times an hour on my production site and am not quite sure how to fix it. I've grepped the source code and I am not using "../" anywhere in my code to generate a path.
My application is running on IIS6 on Win2003 Server. It's using URLRewriter.Net to allow the site to have friendly URLs, and I'm wondering if this could be contributing to the problem.
I've already Googled for a solution and have found several possibilities but none have worked for me.
I've tried creating a new App_Browser file to force the tagwriter settings to use a specific HtmlTextWriter, as suggested in one of the most popular solutions, but that hasn't worked for me. I haven't seen any other likely solutions.
It's probably due to using "~/something", probably on a Hyperlink control. When the physical file is at a different directory level from the friendly URL, ASP.NET uses too many ../'s in the relative URL that it generates, giving this error. If you can't just use an absolute URL instead, I believe that you can use Page.ResolveUrl("~/foo/bar") to get the proper relative URL.
Just set the Enable Parent Paths to True in the ASP settings from your website
That solved the problem for me
Use reflector to dig into the URLRewriter.Net code.
I would give your rewrite paths another once through and see if maybe there is a path that contains a folder that either doesn't exist, has been flubbed or is in fact outside the web application. Can you post the rewrite rule here?
Are you sure that you are causing the error?. Some scripts (Code Red/Nimda) troll the internet looking for a URL traversal that looks like that error.
Is this internal or external? Is it possible that your machine is getting scanned?
I was able to resolve this issue by installing .NET 3.5 SP1.

Resources