To Change the Jquery version of a ASP.NET App - c#

Currently I need to change the jquery version from 2 to 3 of an ASP.NET that is running on an IIS Server.
A vulnerability scanned our server and it created a incident to solve.
I found the file "<IIS_Directory>/Views/Index.cshtml" that has the Javascript references.
#Scripts.Render("~/scripts/vendor")
When I access from a browser I get several scripts instead of ' #Scripts.Render("~/scripts/vendor")'
How do I change the result of the '#Scripts.Render("~/scripts/vendor")' in a production environment?
Constraints
I Only have the publish folder.
At the moment I don't have the code source. until I have the code source I have to apply a patch.

I think you can't do this without source code.
The JQuery library is imported into the BundleConfig.
I think it may be a solution, although not optimal, replace under Scripts JQuery's files with same file of version 3 and give it the same names.

#Scripts.Render("~/scripts/vendor")
Is used to render a script tag (you said there was more than 1 so the bundler must be in debug mode) but the configuration of that bundle will be done in .NET code so you cannot realistically change that without the source code.
Perhaps you could update the actual jQuery source files (using the same file name) on the server and you may get lucky that nothing being used by the other scripts uses anything that has been removed in the move to version 3.
The only way to do it properly and not risk breaking the site is to do it in a proper development environment with the full source code and a proper regression test of all of the sites features.

Related

Website solution requires file not in version control

At my new job there is a C# website which relies on a secrets.xml file which is not in the version control repository. It contains links to databases and passwords. You need to copy it into the root directory manually.
Unfortunately, the existence of this secret file was not properly documented and I set up my solution without it. Worse, the solution builds and runs without it, and the website displays only a generic error when it needs to use the missing file, leading to developer misery.
Main question:
How can I ensure that the build breaks if the file is missing, so it's immediately clear what the problem is?
Follow-up questions:
What could be the rationale for not having the file in version control?
Is there a better way to achieve the objective in 2. than leaving it out of version control?

How to Keep Ace from Looking for Themes and Modes in Current Directory?

I've been working on an MVC web application that uses the Ace in-browser code editor provided by Cloud9. The ace.js script and a script that sets up ace's editor are both in a ScriptBundle together on my BundleConfig. The bundle is being loaded perfectly fine. On my local server, with debug set to true in the web.config, the script worked perfectly fine. However, after launching to a live server with debug set to false in the web.config, several errors appeared.
After fixing a few minor glitches, there remain two errors that I can't seem to understand the cause of. These two errors seem very similar, as they are both 404 not found errors for Ace's chrome theme and Ace's HTML mode scripts. In the script that sets up the editor, they are called as follows:
editor.setTheme("ace/theme/chrome");
editor.getSession().setMode("ace/mode/html");
On my local computer, with debugging set to true, the theme and the mode are set perfectly fine, and everything works as planned. However, as I've said, on a live server with debugging set to false, therefore minifying all of the scripts in my ScriptBundles, I get a 404 error for both the theme and the mode.
When I pull up the JavaScript Console in Google Chrome, I am told of the two 404 errors. The funny thing about the 404 errors, is that they are linking to the current directory of the page I'm viewing, then followed by "theme-chrome.js" and "mode-html.js" respectively. They were never in that directory, and still aren't.
So my question is why do the scripts begin to look in the current directory for their files after being minified? What can I do to fix this issue so that I can keep them minified, in bundles, and have them work? Or is there a way?
Thank you for your help ahead of time.
I find with Ace and MVC Bundling and Minification, I need to set the basePath in the ace configuration using an absolute reference.
ace.config.set("basePath", "/Scripts/FullPathToMy/AceEditorDirectory");
It's probably not the best solution, but it should get you on your way.
The reason why Ace doesn't resolve the base path when you minify is because the minified version is a new unique name that does not match this pattern: ^(.*)\/ace(\-\w+)?\.js(\?|$)/. Ace uses that pattern to find the script element that created it, and uses the src attribute to determine the path.
#Paul's answer is the best, but if for some reason you can't do it that way, Ace also checks for options in attributes that begin with data-ace- that a part of any script tag.
In System.Web.Optimization v 1.10 you can use Scripts.RenderFormat(format, script) to render the script tag to specify the base path.
NOTE: In other Stack Overflow answers they say to use Microsoft.AspNet.Web.Optimization, but this is no longer the case. You may have to use nuget to update your version.
MVC version
#Scripts.RenderFormat(#"<script src=""{0}"" data-ace-base=""/Scripts/ace/""></script>", "~/bundlepath")
Web Forms version
<%: Scripts.RenderFormat(#"<script src=""{0}"" data-ace-base=""/Scripts/ace/""></script>", "~/bundlepath") %>

How to run external executables from an Appharbor application (HTML to PDF generation)?

I have a requirement to produce PDF's for one my .Net web applications currently hosted on Appharbor.
Traditionally, I would simply install latex on the machine, and create PDF's on the fly with pdflatex. This requirement is to display sections in HTML to end users, but also have a downloadable PDF - so it's slightly different.
I have found several (free) external HTML to PDF converters which may be applicable in this instance. However, I haven't found any libraries allowing me to do this purely programatically.
What advice would you give if I plan to continue using Appharbor?
Should I set up a seperate EC2 (or similar) instance to run such an application from? Or is there a better alternative?
I'd recommend using something like DocRaptor. Note that you can probably continue with your current scheme if you place the relevant pdflatex executable (and it doesn't require the entire Latex runtime) alongside the code you push to AppHarbor. AppHarbor will also be introducing background workers, which might be a good fit for this sort of work.
Note that if you're trying to use Rotativa or using wkhtmltopdf with routes obtained from HttpContext you'll need to use this workaround:
http://support.appharbor.com/kb/getting-started/workaround-for-generating-absolute-urls-without-port-number
or install the premotion fix from Nuget:
https://github.com/trilobyte/Premotion-AspNet-AppHarbor-Integration

AutoUpdate using Google Code

I want to make my software autoupdate itself, but I don't have extensive webdesign skills, nor any available website/online hosting. I want to do it in C#/WPF.
So I was wondering if there could be a way to make an autoupdate service using google code, something clean. I'm guessing I'm not the first one to think of it.
I'd do it this way:
1) Use a WebBrowser (silently) and navigate to my google code page. On that page I'd put a field where I enter the latest version number. (I need to somehow find that number in the page's content).
2) I compare that number to the version currently installed (I could put the CURRENT_VER_NUMBER in a *.txt in the software's folder for example).
3) If I conclude that a new version is available, I download it from the "Downloads" tab of my google code project, unzip it, overwrite the files in the installation directory, and restart the app.
First of all, would that work fine? When I imaginate it, it sounds like dirty code.
Then, I wouldn't know how to navigate to the downloads tab, even less how to select the latest version there (maybe by doing a very strict file naming), and download it.
And last but not least, If the application is already running in order to perform the update check, I couldn't overwrite the files without quitting the application, does that mean I have to make some kind of "master app" that performs the check before starting my software? Sounds dirty too =/
Any input is very welcome,
Have a nice day.
I suggest you take a look at ClickOnce. It doesn't require you to create a webpage. You only need to host 2 files: a .manifest file that contains information about your app (version, name and a link to the package that contains your application) and the latest version of your application package. The only thing you need to do is host those 2 files and put a link on your Google Code page to that .manifest file. Users click that link and .net will automatically install or check for the latest version and update if necessary.
You may want to have a look at a library I wrote and released as open-source to do just that transparently - including an external update application to do the actual cold update. See http://www.code972.com/blog/2010/08/nappupdate-application-auto-update-framework-for-dotnet/
The code is at http://github.com/synhershko/NAppUpdate (Licensed under the Apache 2.0 license)
I ran into a few problems, but overall it was not so hard. I think the approach is clean so I'm putting it out there if anyone ever wants to achieve something similar.
You'll have to check out: https://code.google.com/p/theomniscientchimp/ where the full source is available, and of course adjust it for your project.
Thanks for the comments on my original post, made me feel confident i was doing it right =)

Minifying and combining files in .net

I am looking at implementing some performance optimization around my javascript/css. In particular looking to achieve the minification and combining of such. I am developing in .net/c# web applications.
I have a couple of options and looking for feedback on each:
First one is this clever tool I came across Chirpy which via visual studio combines, minifies etc -> http://chirpy.codeplex.com/ This is a visual studio add in but as I am in a team environment, this tool isnt ideal.
My next option is to use an Msbuild task (http://yuicompressor.codeplex.com/) to minify the files and also combine them (maybe read from an xml file what needs to be combined). While this works for minifying fine, the concern I have is that I will have to maintain what must be combined which could be a headache.
3rd option is to use msbuild task just for the minifying and at runtime using some helper classes, combine the files on a per page basis. This would combine the files, give it a name and add a version to it.
Any other options I could consider? My concern with the last option is that it may have performance issues as I would have to open the file from the local drive, read its contents and then combine the files. This is alot of processing at run time. I was looking at something like Squishit - https://github.com/jetheredge/SquishIt/downloads This minifies the files at run time but I would look at doing this at compile time.
So any feedback on my approaches would be great? If the 3rd option would not cause performance issues, I am leading towards it.
We have done something similar with several ASP.NET web applications. Specifically, we use the Yahoo Yui compressor, which has a .NET library version which you can reference in your applications.
The approach we took was to generate the necessary merged/minified files at runtime. We wrapped all this logic up into an ASP.NET control, but that isn't necessary depending on your project.
The first time a request is made for a page, we process through the list of included JS and CSS files. In a separate thread (so the original request returns without delay) we then merged the included files together (1 for JS, 1 for CSS), and then apply the Yui compressor.
The result is then written to disk for fast reference in the future
On subsequent requests, the page first looks for the minified versions. If found, it just serves those up. If not, it goes through the process again.
As some icing to the cake:
For debug purposes, if the query string ?debug=true is present, the merged/minified resources are ignored and the original individual files are served instead (since it can be hard to debug optimized JS)
We have found this process to work exceptionally well. We built it into a library so all our ASP.NET sites can take advantage. The post-build scripts can get complicated if each page has different dependencies, but the run-time can determine this quite easily. And, if someone needs to make a quick fix to a CSS file, they can do so, delete the merged versions of the file, and the process will automatically start over without need to do post-build processing with MSBuild or NAnt.
RequestReduce provides a really nice solution for combining and minifying javascript and css at run time. It will also attempt to sprite your background images. It caches the processed files and serves them using custom ETags and far future headers. RequestReduce uses a response filter to transform the content so no code or configuration is needed for basic functionality. It can be configured to work in a web farm environment and sync content accross several servers and can be configured to point to a CDN. It can be downloaded at http://www.RequestReduce.com or from Visual Studio via Nuget. The source is available at https://github.com/mwrock/RequestReduce.
have you heard of Combres ?
go to : http://combres.codeplex.com and check it out
it minifies your CSS and JS files at Runtime meaning you can change any file and upload it and each request the client does it minifies it.
all you gotta do is add the files u wanna compress to a list in the combres XML file and just call the list from your page / masterpage.
if you are using VS2010 you can easily install it on your project using NuGet
here's the Combres NuGet link: http://combres.codeplex.com/wikipage?title=5-Minute%20Quick%20Start
I did a really nice solution to this a couple of years back but I don't have the source left. The solution was for webforms but it should work fine to port it to MVC. I'll give it a try to explain what I did in some simple step. First we need to register the scripts and we wrote a special controller that did just that. When the controller was rendered it did three things:
Minimize all the files, I think we used the YUI compression
Combine all the files and store as string
Calculate a hash for the string of the combined files and use that as a virtual filename. You store the string of combined files in a cached dictionary on the server with the hash value as key, the html that is rendered needs to point to a special folder where the "scripts" are located.
The next step is to implement a special HttpHandler that handles request for files in the special folder. When a request is made to that special folder you make a lookup in the cached dictionary and returns the string bascially.
One really nice feature of this is that the returned script is always valid so the user will never have to ask you for an update of the script. The reason for that is when you make a change to any of the script files the hash value will change and the client will ask for a new script.
You can use this for css-files as well with no problems. I remebered making it configurable so you could turn off combine files, minimize files, or just exclude one file from the process if you wanted to do some debugging.
I might have missed some details, but it wasn't that hard to implement and it turned out very well.
Update: I've implemented a solution for MVC and released it on nuget and have the source up on github.
Microsoft’s Ajax minifier is suprisingly good as a minification tool. I wrote a blog post on combining files and using their minifier in a javascript and stylesheet handler:
http://www.markistaylor.com/javascript-concatenating-and-minifying/
It's worthwhile combining the files at run time to avoid having to synchronise new versions. However, once they are programmatically combined, cache them to disk. Then the code which runs each time the files are fetched need only check that the files haven't changed before serving the cached version.
If they have changed, then the compression code can run as a one-off.
Whilst there will be a slight performance cost, you will also receive a performance benefit from fewer file requests.
This is the approach that the Minify tool uses to compress JS/CSS, which has worked really well for me. It's Linux/PHP only, but you might get some more ideas there too.
I needed a solution for combining/minifying CSS/JS on a .NET 2.0 web app and SquishIt and other tools I found weren't .NET 2.0-compatible, I created my own solution that uses a syntax similar to SquishIt but is compatible with .NET 2.0. Since I thought other people might find it useful I put it up on Github. You can find it here: https://github.com/AlliterativeAlice/simpleyui

Categories

Resources