Issue with AngularJS/WebAPI application in IIS Website Folder - angularjs

Here is my issue. I have a Angular/WebAPI project hosted in IIS 8 within a subfolder of the domain. When I access the site with a trailing slash after the folder name, everything works ok. But if I leave off the trailing slash, when Angular adds the '#/' for the route, it breaks.
Example: http://www.domain.com/folder/ becomes http://www.domain.com/folder/#/ <- OK
http://www.domain.com/folder becomes http://www.domain.com/folder#/ < - Breaks
The AngularJS Template I started with does not have this issue. I do not understand what is causing this issue and I don't know how to proceed.
Additional Info on the project
I am using MVC Bundles to minimize the javascript and css
I have WebAPI controllers in the same project
I am using Microsoft OWIN for authentication in the same project
Other than this initial URL issue, the project runs correctly.
I can not reproduce this issue in Visual Studio, but VS doesn't run in a folder.
I can post Angular routes if needed.

This is an issue with how relative pathing works in HTML and not something specific to Angular. This is a result of the original specs for URLs and relative links before there was really even a concept of virtual URLs.
Relative links on your HTML page go from the same base as the HTML "doc" itself. Therefore, if the url is:
http://domain.com/folder/
then, your browser anchors relative URLs at
http://domain.com/folder/[relativePathHere]
The browser assumes that it's looking at the default doc (index.html, home.htm, etc.) in that folder -- what originally was an index of the files in that directory. However, without the trailing slash, the browser thinks "/folder" is actually a file called "folder" that is sitting in the root doc directory for the server (as it has no way of differentiating -- it doesn't care one way or the other whether there is a file extension). So, all relative paths are anchored at
http://domain.com/[relativePathHere]
That's why you're having issues with your relative pathing without the trailing slash. To correct this, you will want to put a rewrite rule into place in IIS. This way, you will be immediately redirected to the version that has a trailing slash before the default HTML file is delivered. This is a very common thing to do (not just for this type of case -- it's also important for SEO so that crawlers don't think that there are two distinct pages).
Check out tip #1 in the following link: http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/
Follow the directions for adding the trailing slash, and you should be set.

Related

react-app from subdirectory does not get loaded

I'm working for educational purpose on create a react app and serve it in a subdirectory of an existing domain which already hosts a web application.
Just to try to be more clear I have this situation:
www.mydomain.com (this is a web application currently online)
Now I need to put this new web app under
www.mydomain.com/test
To try to make it work I have my wwwroot folder with my brand new subfolder wwwroot/test.
Now the problem is that if I just put (in wwwroot/test) a simple html file with nothing more than just an <h1> tag, I can open the URL and see the content in it.
If I put my react-app (which work fine in my develop environment) I just see an empty page and if I open the inspector I see that some of the necessary resources aren't reachable because their requests point to root domain (www.mydomain.com/css/ionicons.min.css instead of www.mydomain.com/test/css/ionicons.min.css).
This is my very first time with IIS and I'm trying to get it work by myself, but it seems that I'm unable to find a proper solution to my problem...
Hopefully I was clear enough!
thanks in advance to all who will spent some time reading about this!
I've already made some research and all of them seems to point to some kind of redirect/rewrite rule to write in the web.config of my subdirectory app and/or in the web.config of the root app.
I've also tried to put "homepage": ".", in the package.json which solved the problem of the resources not getting loaded from the proper path but the page is still blank.

Office Add-ins Caching my HTML file

For god knows what reason, Office Add-ins on my local word client is Caching a html file that I dynamically load in (through angular) and refuses to give me a way to remove it from the cache. My only solution is to rename the file and force it to look for a new one.
I know it's a caching issue and not a code issue because when I load the app up inside the web-client it always gets the new version and not the old version.
Please help, renaming files every time I change them is stupid and time consuming
I had the same, not with Angular but JS add office add ins, cut off my webserver and still was able to load the HTML!
For me what worked was the "Clear" button under Trust Centre -> Trusted Add-in catalogues.
Perhaps this is HTML5 - something to do with you manifest, something like this in your HTML, or the equivalent automatically occurring?
`<html.... manifest="/manifest.appcache">
There are loads of suggestion for how to prevent this I haven't tried it yet, but this looks like it contains reasonable examples to test - if imparted in an unusual manner!
http://alistapart.com/article/application-cache-is-a-douchebag
Second option which is now working a treat for me!
In internet Explorer go to Internet Options -> General tab -> Settings -> Temporary Internet files -> tick "Every time I visit the webpage". Naturally this only works for locally hosted sideloading apps.
Oddly enough IE seems to be the object loaded in Office 2016, not Edge, although I have had an Edge message appear in my side-load space, I'll try and grab a shot of it next time I see it (it was during an error it appeared!).
There are a few tricks that might work like this:
What does appending "?v=1" to CSS and Javascript URLs in link and script tags do?
Or in CSS like this:
https://css-tricks.com/can-we-prevent-css-caching/
Today (Win 10 1903 and newest Office 2016) Office AddIns are using Edge as WebViewHost. The WebViewHost seems to store the cached files here:
dir /s %LOCALAPPDATA%\Packages\Microsoft.Win32WebViewHost_cw5n1h2txyewy\AC\#!123\INetCache\
In our case we are using Azure App Service (IIS) as backend for our Office AddIn.
And we added the following web.config setting to let the client re-validate all cached files on each access:
...
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="0.00:00:00" cacheControlCustom="must-revalidate" />
</staticContent>
...
Of course, the cacheControlMaxAge may be adjusted to your needs.
Hitting Ctrl + Shift + F5 helped for me.
An easy workaround for this would be to append some random query string at the end of the url, thus making sure your browser has a cache miss.
For example, instead of getting the file http://myaddin/myfile.html, append a big enough random query string parameter so that you instead query for http://myaddin/myfile.html?cache=s98sj398nf03984jf3498n.

SocialEngine staticBaseUrl is not working in production mode

I am using socialengine as content management system, when i change the socialengine site to production mode it did not load the css file, I figured out that my $staticBaseUrl function is not returning the website name.
I manually added the path in default layout to load the css file, it works but a font family (centurygothic) is not loads. I am using SocialEngine's 4.2.4 version, please help.
I am using plesk panel for as hosting server.
If you use paths in your css file (theme_name/main.css or Modulename/externals/styles/main.css), you can use following way of indicating path:
~/application/..., where ~ will be automatically parsed and replaced by staticbaseurl.
Firstly no need to manually adjust the $staticBaseUrl in the layout. There is a setting in the admin panel (general settings) where you just specify what the URL is. This is commonly used to set the CDN URL.
Secondly, most of the CSS files in production get minimized and appended to each other, so you will only see one query similar to this: /application/css.php?request=application/themes/default/theme.css
Thirdly, if there is still an issue there may be a number of reasons. For example, are you using the http://example.com/home or http://example.com/index.php/home URL format?

Redirect script making image referencing impossible

I have a site that I run off the back of another site. In order to save on hosting etc. the domain points to a script and depending on the url that is in the address bar it redirects accordingly to a subfolder which holds the separate sites. I am happy with this and it works a treat. So when it hits url 1 it goes to "www.domain1.com/url1/Home/Index" and when number 2 is typed in it goes to "www.domain2.com/url2/Home/Index". url1 and url2 being the subfolders.
The problem comes when i am developing another site that is going off the back of the original. i have the site developed in vs and am about to release and obviously all of the image urls, script urls etc are completely wrong as they don't take into account the subfolder within the site. they all used /images/site/image1.jpg etc. this means that they are looking from the root and not from my subfolder url.
is there a simple way of implementing this so that i can develop it using vs and not have to change every image reference every time i release code?
i realise this probably has an incredibly easy answer to my problem - i just can't seem to find anything that fits.
Any suggestions?
slight addition to this - when my site loads it loads to the default page - and therefore when i use ../images/site etc this works when the url contains Home/Index, but not when it hits it on the default url which doesn't include the folder and page qualification.
Just noticed this was left unanswered. When referencing in MVC you need to use the tilde (~) to reference the route of the application. So in my instance i have two sites and using the tilde notation if referenced the route of the application, of which each were specified as different routes.

how to remove sitemap.aspx in dnn6

i need to remove sitemap.aspx from the site.
In dnn 6,there is a sitemap.aspx page that simply shows an xml sitemap.i cannot edit/remove that file.so i need to remove that page and recreate it with a simple html sitemap.
NOTE:the page name should be sitemap.aspx
Sitemap.aspx isn't a physical page you can delete.
You can, however, rename it to something else. It's in your web.config file, under the 'handlers' section. Just look for sitemap.aspx, and change it to something else, like 'searchenginesitemap.aspx'. Don't forget to update your robots.txt file to point to the new sitemap name, or go to the various webmaster console pages in search engines and advise them of the new location.
The sitemap.aspx is used to create the xml sitemap for search engines. By changing this you break this functionality and limit the search-ability of your site.
That being said, in Host Settings->Advance Settings you could setup a new Friendly Url that would match .*/sitemap.aspx to another url/page on your site.
I have long stopped using DNN's native sitemap.aspx... ITS BUGGY!... and here is how i found out.
I generated my own "CLEAN" sitemap.xml using a free 3rd party tool. And uploaded it to the root of my DNN website.... re-submitted the the domainname.com/sitemap.xml to Google via web master tools and as a result we now get a 1ST PAGE and TOP 10 RANKING.
Mostly in the top 5... where as before using DNN's native sitemap.aspx we would get random errors which was pretty ANNOYING. Plus we got very bad Google Page Rank, But those were just my findings of better results. Note:I also place the location of the sitemap within the robots.txt file...
Although i will admit that it is extremely ANNOYING that you cannot just edit the DNN Sitemap url. This creates an issue if you've built the the site on a test server and then migrate over to production... your DNN Sitemap url only reads the firs portal alias from when you first developed the site.
Anyway, this was my findings... others may vary... just sharing.

Resources