PageSpeed Insigths and GoDaddy Windows Hosting - html

I'm having an issue with cache in my webpage.
My webpage is hosted by GoDaddy, with the Economic Windows Server with Plesk.
conexaomktdigital.com.br
It's a very simple site, I DONT USE PHP on it, only HTML, CSS and simple bootstrap JS.
When I run PageSpeed Insights, the results are telling me to optimize browser cache, including adding expire dates to my .css and images.
Mobile: 60/100
Desktop: 75/100
HOW I DO IT? I seek everywhere and don't see anything, everybody talks about .htaccess, but it's not apache, it's windows with plesk by GoDaddy... What should I do, can someone help me?

Create and use a correct 'Web.Config' file. put it in your root folder.
You can find some information about how to use a web.config file with te right tags here:
https://www.giftofspeed.com/leverage-browser-caching/
I use a very simple configuration, it appears to work nice for me:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" />
<asp scriptErrorSentToBrowser="true"/>
<caching enabled="true" enableKernelCache="true">
<profiles>
<add extension=".html" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange"/>
<add extension=".css" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange"/>
<add extension=".js" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange"/>
<add extension=".jpg" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange"/>
<add extension=".png" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange"/>
</profiles>
</caching>
</system.webServer>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true"/>
</system.web>
</configuration>
this will keep the files listed there in cache until it have some change.
No Error 500 for me, I think it will not happen to you too.

Related

Redirect using web.config file when there is no pathname

I've been working on a ASP.NET web application project in Visual Studio. In that project, when the user enters the hostname they get a 404 error but what I would like to happen is for them to be redirected to the index.html when they have just entered the hostname.
Below is the code that I tried using but it didn't work. It said there were too many redirects which I think has something to do with the path value being empty
<location path="">
<system.webServer>
<httpRedirect enabled="true" destination="index.html" httpResponseStatus="Permanent" />
</system.webServer>
</location>
Does anyone have an suggestions?
If you are using MVC you could create a default route but since you asked for a way to do it in web.config try:
<configuration>
<system.web>
<customErrors defaultRedirect="index.html" mode="On">
<error statusCode="404" redirect="index.html"/>
</customErrors>
</system.web>
</configuration>

Error 404 on Angular 2 app when deployed to Azure

I have an angular 2 app with a simple server.js as a node.js BE.
I have deployed my application to Azure and I'm at the point that the application loads and shows me the welcoming page.
When I reach a component that tries to read a local JSON via an HTTP request I'm getting a 404 error (that I don't receive in my local environment).
The code to read the json is the following:
private ReadFromJson(path: string): Observable<string[]> {
return this._http.get(path)
.map((response: Response) => <string[]>response.json())
.do(data => console.log('All: ' + JSON.stringify(data)))
.catch(this.handleError);
}
where the actual path passed is the one showed in the console.
I have done two things: First I made sure that the file is actually there using the Azure CLI, and it is there as expected.
Secondly, after viewing many posts the only other solution I found was to add the MIME type as suggested here, but that didn't work for me as well.
I would really like some help in understanding and be troubleshooting the problem, any suggestion is welcomed!
Update:
If your app is just front-end (Angular) app, then you no longer need to serve these static files via Node.js. Because by default Azure App Service have installed IIS on it and IIS can serve any file type by doing some configuration. So, in this case, you can just keep web.config looking like below and put it to "site/wwwroot/dist".
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".json" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
</configuration>
As you deployed a Node.js on Azure App Service, which would host your app using iisnode, and you probably have a web.config file that looks like the content in this link.
By default, this configuration file assumes the static file in the /public folder.
<!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
<rule name="StaticContent">
<action type="Rewrite" url="public{REQUEST_URI}" />
</rule>
So, after you add this to web.config,
<staticContent>
<remove fileExtension=".json" />
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
please make sure the static files were put into /public file.
I ran into the same problem last week and thought maybe i should share my findings since i got it to work as desired.
I deployed the app developed using angular cli and built using the same. I copied over all files in the /dist folder over to azure and added a web.config (this was a lot of hit and trial) but i learned that a rewrite rule for angular was required which can process the webpack bundled assets and not return a 404.
Here is the web,config and i believe it should work for you as-is:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<httpRuntime maxQueryStringLength="32768" maxUrlLength="65536" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxQueryString="32768" />
</requestFiltering>
</security>
<rewrite>
<rules>
<rule name="AngularJS" stopProcessing="true">
<match url="^(?!.*(.bundle.js|.bundle.map|.bundle.js.gz|.bundle.css|.bundle.css.gz|.png|.jpg|.ico|.svg|.eot|.woff|\​.woff2)).*$" />
<conditions logicalGrouping="MatchAll"></conditions>
<action type="Rewrite" url="/" appendQueryString="true" />
</rule>
</rules>
</rewrite>
<staticContent>
<remove fileExtension=".svg" />
<remove fileExtension=".eot" />
<remove fileExtension=".woff" />
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
<mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
<mimeMap fileExtension=".woff2" mimeType="application/font-woff" />
</staticContent>
</system.webServer>
</configuration>
<!--
This is required for the app to work in Azure or an ASP.NET hosting environment because the woff files
are not treated as static content on Azure as well as the routing breaks without the rewrite rule below
and app or rather the server returns a 404.
-->
Below suggestion worked wonders.
If your app is just front-end (Angular) app, then you no longer need to serve these static files via Node.js. Because by default Azure App Service have installed IIS on it and IIS can serve any file type by doing some configuration. So, in this case, you can just keep web.config looking like below and put it to "site/wwwroot/dist".
Adding web.config worked
Thanks for excellent solution.

http redirect loop using location in web.config

I have a website inside which I have a directory I want to keep private. My login page is inside this directory called admin.aspx.
In my main Web.Config I have the following block:
<authentication mode="Forms">
<forms loginUrl="~/Account/admin.aspx" name=".ASPXFORMSAUTH"></forms>
</authentication>
And then in my subdirectory I have a second web.config file with the following:
<location path="admin.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
However when I try to get to admin.aspx I get this error:
The web page at http://localhost:51167/Account/Login?ReturnUrl=%2FAccount%2FLogin%3FReturnUrl%3D%252FAccount%252FLogin%253FReturnUrl%253D%25252FAccount%25252FLogin%25253FReturnUrl%25253D%2525252FAccount%2525252FLogin%2525253FReturnUrl%2525253D%252525252FAccount%252525252FLogin%252525253FReturnUrl%252525253D%25252525252FAccount%25252525252FLogin%25252525253FReturnUrl%25252525253D%2525252525252FAccount%2525252525252FLogin%2525252525253FReturnUrl%2525252525253D%252525252525252FAccount%252525252525252FLogin%252525252525253FReturnUrl%252525252525253D%25252525252525252FAccount%25252525252525252FLogin%25252525252525253FReturnUrl%25252525252525253D%2525252525252525252FAccount%2525252525252525252FLogin%2525252525252525253FReturnUrl%2525252525252525253D%252525252525252525252FAccount%252525252525252525252FLogin%252525252525252525253FReturnUrl%252525252525252525253D%25252525252525252525252FAccount%25252525252525252525252FLogin%25252525252525252525253FReturnUrl%25252525252525252525253D%2525252525252525252525252FAccount%2525252525252525252525252FLogin%2525252525252525252525253FReturnUrl%2525252525252525252525253D%252525252525252525252525252FAccount%252525252525252525252525252FLogin%252525252525252525252525253FReturnUrl%252525252525252525252525253D%25252525252525252525252525252FAccount%25252525252525252525252525252FLogin%25252525252525252525252525253FReturnUrl%25252525252525252525252525253D%2525252525252525252525252525252FAccount%2525252525252525252525252525252FLogin%2525252525252525252525252525253FReturnUrl%2525252525252525252525252525253D%252525252525252525252525252525252FAccount%252525252525252525252525252525252FLogin%252525252525252525252525252525253FReturnUrl%252525252525252525252525252525253D%25252525252525252525252525252525252FAccount%25252525252525252525252525252525252Fadmin%25252525252525252525252525252525253FReturnUrl%25252525252525252525252525252525253D%2525252525252525252525252525252525252fAccount%2525252525252525252525252525252525252fadmin has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.
I don't understand why it's got itself in a loop. If I change web.config (inside the directory) to simply say:
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
I can get to it so is it something with the location option?
Thanks.

The connectionstring property is not initialized

So, I realize that there are a lot of questions on here pertaining to this problem, but none seem to be the same as to what I'm dealing with. I had to delete my dataset out of visual studio and bring it back in. After doing so I got the error. I'm using mysql as a backend, so I'm using the dotconnect for mysql extension for visual studio. Everything was working fine until I did this step. Here is my app.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="RMSteel.My.MySettings.RMSteelConnectionString" connectionString="User Id=rmsteel;Password=password;Host=192.168.0.46;Database=RMSteel;Persist Security Info=True"
providerName="Devart.Data.MySql" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
Whenever I use my connection I use the name RMSteel.My.MySettings.RMSteelConnectionString, since this is auto-generated (I assume by dotconnect). I am fairly far in this project and would like to find a fix using this connection string, so I don't have to rewrite that much. Thanks for any help, and if you'd like me to post more code, I can.

Allow MDB Downloads in IIS7

Currently if I am hosting an Access .MDB file to allow users to download, IIS7 is throwing a 404 error. I know the file is there and the permissions are fine. It appears to be a Handler issue, but I cannot figure out how to change the handler to allow downloading of MDB file. I assume I need to add something to the Handlers section of the web.config, but I am unsure of the syntax.
Thanks.
Or, if you don't want to modify a system-wide configuration file, you could add the following lines to that section in your web.config:
<remove fileExtension=".mdb" />
<add fileExtension=".mdb" allowed="true"/>
For example your Web.config should be similar to this:
<configuration>
<system.webServer>
<security>
<requestFiltering>
<fileExtensions allowUnlisted="true" >
<remove fileExtension=".mdb" />
<add fileExtension=".mdb" allowed="true"/>
</fileExtensions>
</requestFiltering>
</security>
</system.webServer>
</configuration>
Also see http://www.adamwlewis.com/articles/iis-7-not-serving-files-4047-error.
OK, found it.
Just need to remove the following line:
<add fileExtension=".mdb" allowed="false" />
in the "requestFiltering" section from the \Windows\System32\inetserv\config\applicationHost.config file.