ClientDependency RequiresCss refresh - c#

I'm using the following code these days to include my JS and CSS files within my (Umbraco) websites:
#using ClientDependency.Core.Mvc;
#{
Html.RequiresCss("link-to-file", 1);
Html.RequiresCss("link-to-file", 2);
Html.RequiresJs("link-to-file", 1);
}
I've noticed that the following files is being called when loading the site:
https://mysite.nl/DependencyHandler.axd?s=L2xpYi9zY3JpcHRzL21vZGVybml6ci5jdXN0b20uanM7L2xpYi9zY3JpcHRzL2pxdWVyeS5kbG1lbnUuanM7L2xpYi9zY3JpcHRzL3NpdGUuanM7&t=Javascript&cdv=1511701721
After making changes to either the CSS or JS files and uploading them to the server, the DependencyHandler call remains the same. Therefor, the CSS and JS are being cached on the server and I don't see my changes on the live site.
I need to manualy change the ClientDependency version (within ClientDepenedency.config). If I change that, the 'cdv' value at the end of the DependencyHandler call is changed (to the version I changed it in ofcourse), and the new files are being served.
Is there a way to get the DependencyHandler notice changes in the files and automaticly refresh the cache?

If anyone is still ask this question, as a response, you can enter
Shift+F5
on search engine.
Maybe, it is a response this question.
By the way if you were doing <compilation defaultLanguage="c#" debug="true" ...> in Web.config, you can look js or css files.
If this problem isn't cache problem, should been controled server connection, services,.. Except that, if it is a OOP's problem, wouldn't umbraco throw a mistake? As I said, I understood this text as a cache problem and I response as it.
Hope it work.

Related

CSS file updates don't apply in ASP .NET CORE

I have a CSS file for my homepage, it's just a simple transparent background image.
When I change something in that file, it does not apply the changes, older version is compiled.
Even if delete that file completely from computer, it still loads it (I saw that within inspect element).
My view has just link to that CSS file and nothing else. It has defined Layout page also.
It's happening to me all the time. If I create some other as source, it works but I get the same problem for that new file also after the initial version.
What could itbe ? I'm fairly new in ASP .NET CORE but it looks like it's storing those files in a server. One time I accidentally opened console in inspect element and got some bad connection error and it worked from that point on.
Sounds like your browser is caching your css file. A common way to force it to use the updated version is to add the attribute asp-append-version="true" to all your link and script tags so that your browser always fetches the most up to date version.

Serve files dynamically instead of statically

Following this answer, I've enabled serving JavaScript and CSS from my Views folder which is helping my project's organization. Unfortunately, while I'm developing, I find I have to disable my browser cache in order to see my changes. I'd like to be able to develop without keeping DevTools open just to disable the cache.
I figure my issue is the System.Web.StaticFileHandler serving up the files in such a way that the browser caches them. I've tried using System.Web.Handlers.TransferRequestHandler like this answer suggests, but then I get 500 Server Errors instead.
Is my understanding of the problem correct? How can I resolve my issue?
Note: Not that it's relevant, but I intend to add a config transform to switch back to the static handler for releases.

Can people find and download the Code File linked to your aspx page?

So I imported this aspx page done by a former dev who worked for the company I'm in now. I found that the aspx page left by him doesn't have a codebehind file so I assumed this wasn't the source code. I can't find the source so I added a code file and try to work it out on my own. But my main concern is this: clients can't access the code behind, right? Is a manually added code file subject to the same protection?
The codebehind file is there as a place to put your server side code. However it's technically not necessary to have one since you can put the code in the aspx file using c# script tags. It's however recommended to put it in the codebehind file for better separation between markup and code.
It does not matter if you add it yourself or if Visual Studio adds it for you. It does not change anything in terms of access. In all events it executes on the server.
If your server is properly configured to run ASP.NET applications - which I believe it is - then IIS will not serve .cs files to a client. These will normally be accessible only through FTP. Try it yourself, by browsing to any .cs file in your application :)
Also notice that what you get when you browse to an .aspx file is not the very same code you'd see in Visual Studio, but the result of that being processed. IIS will serve the resulting HTML. So even if you have server side code in the ASPX file, that won't be visible to an end user browsing through your application.
Sounds like a web application project; in this case, the code is in the code-behind file as #TGH mentioned, and the code would be in the DLL compiled for the web application. Therefore, the only way to get that code is use a tool like Telerik JustDecompile, and decompile that DLL to grab the source code for EVERY file in the project. It would be much better to have the source, as these decompile tools do not include everything in that code-behind file.

Clearing cache once on deploy

I'm trying to figure out how the easiest way would be to force endusers browser to clear cache.
We are working in visual studio with .Net WebForms and AngularJs
So every time we deploy our .Net project to test or production enviroment we got problems with cache saving old javascript and hides new implementation...
I know a couple solutions but I wanna see if there are any other?
Thanks in advance!
Right click in this page and select view source, you will see static files suffixed as follows:
<script src="//cdn.sstatic.net/Js/stub.en.js?v=b1fcfe635df7"></script>
Basically this is kind of the best method, generate some suffix and append that to the end of all of your static files as a querystring parameter. That will force the browser into thinking that the file is new, i.e. if the querystring has changed...
The rub here though is how often do you change those files... how often do you want to force the user to download new static files... using a generated timestamp could force the user to download the file everytime they visit the site, often not ideal.... Maybe use the web.config date or something like it.
you can add below settings in web.config to disable caching
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>

Deploying an ascx control

I have a fix done for my user control.
The changes are there both in the .ascx file and the .ascx.cs file.
Now, post-build...is there any way I can deploy just my...assembly for this control container...and avoid the deployment of the .ascx file?
Although the assembly contains some pre-compiled methods, the .ascx page is still "interpreted" (technically it's compiled, but IMO it's easier to think of it as interpreted) every time the page is requested (well, not every time, since it's often cached, but certainly the first time changes are made). Try it for yourself -- make a change to some of the markup in a .ascx file and then request the page -- you'll see that your changes are reflected in the response (you may have to restart the site if it's cached).
So, following from this, you will need to deploy both of the files, as both are used by IIS to service a request.
On another note, you can sometimes run into strange problems when just deploying a single assembly (or maybe it's just me being paranoid because I thought this happened to me once) to a live site -- it's safer to deploy the entire site at once. Unrelated to the question itself, but I thought I'd note it.
no .. if you have done change in the .ascx file you should upload that too..
Because the ascx file has changed and as it's markup code does not go into the compiled assembly of the control, for reflecting the changes, you'd need to deploy both the assembly (which contains the ascx.cs code) and the ascx file.

Categories