I am working with the old Spring Batch Admin project (I know it is no longer supported). I have it working with Spring framework 5.1. I recently upgraded to 5.3.4 and started seeing problems. Spring Batch Admin uses freemarker templates to generate html, json, or rss. Users determine the output by adding an extension to the URL (for example ".json" or ".rss"). The default with no extension is for the html rendering.
The URL parsing changes that is part of 5.3 (https://spring.io/blog/2020/06/30/url-matching-with-pathpattern-in-spring-mvc) is causing problems. It matches /job/execution/1.json with the right URL /job/execution/{jobid} but the URL template variable is jobid=1.json instead of jobid=1. This causes a problem with the method invocation because it is trying to match a long variable with the string "1.json".
I realize that adding an extension to a URL is not the current approach to returning different results with content types. Anyone have an recommendation for a path forward?
The issue and solution are discussed here. https://github.com/spring-projects/spring-framework/issues/26119
Related
I am working on .Net(C#) application. It's a quite old application and has classic Asp pages, Web Forms and MVC pages. And using single page application concept to load all these pages. All of them have different-different CSS and JS based on business logic they have.
Now the problem is, every time after our release we face same issue that is CSS and JS caching. I know there are couple of ways to deal with this issue, the most common is adding a version and change this version with every release. But the problem is we have thousands of such links so updating all of then I don't find it a solution that we should opt.
Another approach what we thought of is, we can have a module that intercept all the resource requests and we update the link for each CSS and JS file and add some version (what I mentioned in above paragraph). But the problem I can see here is, this will make application slow because of checking and executing some string (File path) manipulation code for each resource requests.
I am sure I am not the only one who is facing this problem, so if anyone can share their experience and approach to handle this problem with minimum changes in code.
As #tim suggested adding query string to the files will help you.
Considering the volume of changes required at your end, I think preparing a rewrite rule for .js and .css files (with pattern matching) and injecting the query string to target URL (with permanent redirection) will help you.
solution for similar query is available here
Please note that, with each build you might need to tweak the configuration as necessary.
What might help: it isn’t necessary to include a version number in your files. It is sufficient if a versionnumber exists in your link.
You could use a (fake) querystring for that. So instead of linking to your css or js file like “style.css” you could link to “style.css?version=1.02”. This querystring part is ignored, but the browser thinks it’s a new file.
Maybe you can go through all of your links one time; make them serverside (in case of webforms) and add this versionpart serverside based on the version of your build. Then for your next releases the problem is solved..
I have some asp.net c# code that grabs the path name and uses it for various authorization and authentication tasks. In our web site project, this is what returns the path (with extension, for example: index.aspx?querystringparam1=3&qp2=4):
string strPath = HttpContext.Current.Request.RawUrl;
This used to return "index.aspx?querystringparam1=3&qp2=4".
However, in our work to convert to a web application project, that same line of code is now returning the url WITHOUT the extension: "index?querystringparam1=3&qp2=4".
How I can get the old behavior to return? It seems to be an IIS setting somewhere because going back to the website project on the same IIS instance does not revert to the old functionality.
OK. I found the problem. Looks like Visual Studio, in its infinite wisdom, installs two packages that make up Microsoft Friendly Url (DynamicModule_Microsoft.AspNet.FriendlyUrls.FriendlyUrlsModule), which removes extensions from path files by sending a permanent redirect to the browser before even reaching the site code.
And, removing those NuGet Packages (there are two), solves the problem!
My Spring MVC application has many public-facing pages with URLs in this format:
http://www.example.com/?productId=123456
Somewhere along the way, a major search engine picked up an extraneous URL and started spidering thousands of pages with a corrupt URL (note the ;) in this format:
http://www.example.com/;?productId=123456
Strangely, Spring MVC completely ignores the ;. How can I detect this extraneous ; and issue a redirect to the correct URL?
Apparently nothing available in Spring MVC, so I just placed a simple ServletFilter in front of it.
I am trying to ensure that stale images/js/css files in a cache will not be used after deploying a new version of an asp.net web application.
I'm currently looking in to the js aspect of this. First, ALL of my own scripts are registered through the System.Web.UI.ScriptManager with normal urls to js files. So, I've subclassed the ScriptManager and I tack a ?ver='x.x.x.x' on the end of the script url. I don't see any problem with that for my scripts with normal urls, however there are always a lot of ScriptResource.axd references and I am concerned about these scripts.
So, for example, lets say in my next version I update the AjaxControlToolkit dll. Will the scriptResource.axd urls be different from the urls used by the previous AjaxControlToolkit? The scriptResources.axd look pretty funky to me, so I am hoping they are generated with a hash of the assembly or something? I've been through a ton of literature on scriptResource.axd, but I haven't found anything on this topic. Anyone have any ideas?
Thanks for reading.
You're partially right. The format of resource URL is WebResource.axd?d=encrypted identifier&t=time stamp value. The "d" stands for the requested Web Resource. The "t" is the timestamp for the requested assembly, which can help in determining if there have been any changes to the resource.
In brief, the first parameter is encrypted assemblyName + "|" + resourceName value (by using internal Page.EncryptString method); the secondparameter is number of ticks of assembly was last written to date (by using File.GetLastWriteTime method).
So, using the next version or your assembly will change the resource URL (rebuild the assembly and/or change its version).
More information could be found here:
Working with Web Resources in
ASP.NET 2.0
WebResource.axd or how I learned to
love the embedded resource
In my research, I found 2 ways to do them.
Both required modifications to the Application_BeginRequest procedure in the Global.Asax, where you would run your code to do the actual URL mapping (mine was with a database view that contained all the friendly URLs and their mapped 'real' URLs). Now the trick is to get your requests run through the .NET engine without an aspx extension. The 2 ways I found are:
Run everything through the .NET engine with a wildcard application extension mapping.
Create a custom aspx error page and tell IIS to send 404's to it.
Now here's my question:
Is there any reason one of these are better to do than the other?
When playing around on my dev server, the first thing I noticed about #1 was it botched frontpage extensions, not a huge deal but that's how I'm used to connecting to my sites. Another issue I have with #1 is that even though my hosting company is lenient with me (as I'm their biggest client) and will consider doing things such as this, they are wary of any security risks it might present.
`#2 works great, but I just have this feeling it's not as efficient as #1. Am I just being delusional?
Thanks
I've used #2 in the past too.
It's more efficient because unlike the wildcard mapping, the ASP.NET engine doesn't need to 'process' requests for all the additional resources like image files, static HTML, CSS, Javascript etc.
Alternatively if you don't mind .aspx extension in your URL's you could use: http://myweb/app/idx.aspx/products/1 - that works fine.
Having said that, the real solution is using IIS 7, where the ASP.NET runtime is a fully fledged part of the IIS HTTP module stack.
If you have the latest version of IIS there is rewrite module for it - see here. If not there are free third party binaries you can use with older IIS (i.e. version 6) - I have used one that reads the rewrite rules from an .ini file and supports regular expression but I cant remember its name sorry (its possibly this). I'd recommend this over cheaping it out with the 404 page.
You have to map all requests through the ASP.NET engine. The way IIS processes requests is by the file extension. By default it only processes the .aspx, .ashx, etc extensions that are meant to only be processed by ASP.NET. The reason is it adds overhead to the processing of the request.
I wrote how to do it with IIS 6 a while back, http://professionalaspnet.com/archive/2007/07/27/Configure-IIS-for-Wildcard-Extensions-in-ASP.NET.aspx.
You are right in doing your mapping from the database. RegEx rewriting, like is used out of the box in MVC. This is because it more or less forces you to put the primary key in the URL and does not have a good way to map characters that are not allowed in URLs, like '.
Did you checked the ASP .Net MVC Framework? Using that framework all your URLs are automatically mapped to Controllers which could perform any desired action (including redirecting to other URLs or controllers). You could also set custom routes with custom parameters. If you don't have seen it yet, maybe it will worth the look.