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

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.

Related

ClientDependency RequiresCss refresh

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.

.net site causes file download instead of showing specific pages

On a customers site certain pages (two that I know of) trigger the download of a TeamViewer exe file that is on the server instead of showing the linked aspx page.
This was brought to our attention today and I'm not sure when it started.
I've gone over the routing and generic page handler in our system and I don't find anything out of the ordinary.
Is there any known reason this could happen that relates to server configuration or similar?
I've tried it in multiple different browsers and the download is triggered in each of them (Chrome, Chromium and Opera).
The file in question is not linked in the pages. The contents of the pages are being fetched from a database using the same system as the non-problematic pages.
I found the issue.
Turns out someone added a redirect to this exe file in web.config which matched "tv" (for TeamViewer) in the url, and matched for example "tjanster-programutveckling" which was one of the problem pages.
I guess whoever added that redirect expected it to only apply to the whole url, not just a partial match.
I've commented out this redirect and now the pages load properly.

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.

How to change a website default document programmatically on the fly

Using ASP.NET 4.0, IIS 7.5.
I have a website engine, I have just implemented a way for this to tell if it's being loaded on mobile and instead of loading Controls\MyControl.ascx it loads Mobile\Controls\MyControl.ascx. This works well for my controls and also my MasterPage.Master file.
What I can't figure out however is how I can do the same with Default.aspx. This needs to be done on the fly programatically as I need to be able to check if it's mobile version. I was thinking of doing something on a pre-init event in globals but not sure if that's the best way.
Note: I don't want to use inline code on Default.aspx and just display different content base on my Mobile flag as my scenario goes one step further by basing the file on customer as well and this would mean having one huge Default.aspx for all customers which wouldn't be manageable.
Changing the default document on the fly is not possible in any practical sense.
Writing to the web.config on the fly to load a mobile version of a default page is quite frankly terrible and not an answer to the true context of your issue. I would feel irresponsible as a developer if I even proposed this as an answer to loading a mobile version of a default page.
I was trying to help you solve your problem and not just answer the base question in the title. As we all know, changing the web.config will restart your application and would not serve as a true solution, as you could not do this and achieve any kind of performance.
Here is the BEST alternative (IMHO) to dealing with mobile browsers.
http://51degrees.codeplex.com/
HTH!
For anyone else looking at this I have found a solution but I am not sure I will implement it as I don't like the idea of updating the web.config file at run time. Using the Microsoft.Web.Administration namespace you can update the server.webServer -> defaultDocument section programmatically. Doing this allows you to change the path to default.aspx and it will load based on the variables you set.
This link should provide more information: http://blogs.msdn.com/b/saurabh_singh/archive/2007/11/24/accessing-iis-7-0-features-programmatically-from-configuration-file-s-c.aspx
Also, the Microsoft.Web.Administration dll isn't available directly in VS so you need to add it from %windir%\syswow64\inetsrv (64bit version).

error while integrating blogengine.net 2.0 to a website

I was integrating the blogengine 2.0.what i did is
created folder inside my project called blogs.
copied all the files from the blogengine.net 2.0 (web).
made changes in the web.config and changed master page path.
as per
http://www.ajaymatharu.com/integrating-blogengine-into-an-existing-site/
4.while running the project it is showing the error in styles.
the screen shoot of the error is...
screen shoot of the project solution explorer is.
web.config file...
Probably not the answer you're looking for but I would go the sub-domain route and avoid all of these issues completely. Also makes it easier to maintain and upgrade. Every time there is a BE upgrade you potentially face similar issues by trying to integrate it into an existing site.
Here's one I did already: http://homenetdirect.com/
All I had to do was customize the blog CSS to match that of the parent site - you might even create a "complimentary" design...

Categories