Resolving js and css urls affected by app.Map in ASP.NET 5 - asp.net-core

I am implementing multi-tenancy based on the first folder segment of the request url.
As such I'm configuring each tenant separately by branching with IApplicationBuilder like this:
PathString path = new PathString("/somefolder");
app.Map(path,
branchApp =>
{
// code goes here to configure the branch
}
as a result of this if my view has a link with url /Home/About for example, it automatically is adjusted to be relative to the folder I branched on when I visit /somefolder, ie the links change to /somefolder/Home/About, somefolder/Home/Contact etc
This was kind of unexpected to me but actually helpful.
But also if my view has
<link rel="stylesheet" href="~/css/site.css" />
<script src="~/js/lib/jquery/dist/jquery.js"></script>
those now resolve to /somefolder/css/site.css and /somefolder/js/lib/jquery/dist/jquery.js
which is not what I want.
Is there some way I can change this behavior for js and css but keep it for navigation links?

No, you can't. At least, not easily: when using app.Map, it automatically sets HttpContext.Request.PathBase with the path parameter you specified, which causes the exact behavior you're seeing (it's basically a "virtual directory" equivalent).
The best option is to stop using virtual path links (~/) and replace them by standard root-relative links (/), that are not processed by Razor and MVC.
<link rel="stylesheet" href="/css/site.css" />
<script src="/js/lib/jquery/dist/jquery.js"></script>

Related

Shopify add new index.html page with url https://myshopifyshop/index.html

I am working with external tracking service. They sent my index.html file, which looks like this:
<html>
<head>
<!-- tag -->
<script type="text/javascript" src="//path.js"></script>
</head>
<body>
</body>
</html>
They want us to upload this file to shopify and sent them the url to it. The url should look like this https://myshopifyshop/index.html. I couldn't find any article how to upload or create new blank html page with .html extension. Is this somehow possible?
You can't create an html page that will follow the root url of your site.
But you can upload a html page as an asset and link that asset as a page.
Example url will be:
https://cdn.shopify.com/s/files/1/*****/*****/t/4/assets/index.html
But I don't think that this will do you any good, since tracking services requires you to track the current site and not a dummy file that no one will ever open.
It's highly possible that the only important part is the script and everything else is not needed.
So you actually may need to add the script in your layout/theme.liquid file and ignore the rest.
Please contact the the tracking service and let them know that you are not using a static HTML site, but a Shopify one and what steps should you follow.

After deployed to server, website UI does not display properly

I have an ASP.Net MVC5 based web app. I am using Bootstrap for the UI.
On my machine everything is perfect. After login, the following page is shown.
Analytics page as on localhost
After I deploy to the web server, I get the following page post login.
Analytics page from the server
You can see that the page from server is all messed up. It is almost like all divs are showing up with their borders. I am not sure what is going wrong here. Any inputs are most welcome.
Update:
I have another application "TalkApp" that has the same login page as this Analytics App. "TalkApp" UI has no issues.
So I checked the page source for the login page. The TalkApp has these links:
<link href="/TADATalk/Content/bootstrap.css" rel="stylesheet"/>
<link href="/TADATalk/Content/site.css" rel="stylesheet"/>
<script src="/TADATalk/Scripts/modernizr-2.8.3.js"></script>
<script src="/TADATalk/Scripts/jquery-3.1.1.js"></script>
<script src="/TADATalk/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="/TADATalk/Scripts/jquery-ui-1.12.1.js"></script>
<script src="/TADATalk/Scripts/bootstrap.js"></script>
Whereas, the AnalyticsApp did not have these. Instead it had ..v="e34hgd5677.." type of entries. I removed use of bundles from AnalyticsApp and directly added the link refs. Now the UI loads properly.
So the question still stands: why did bundles not work with one app but work with another app (which is also deployed on the server).
The only thing I can think of as to why your bundles aren't loading but hardcoding css links does, is if you're not including them in your _Layout.cshtml. Here is an example from my application.
BundleConfig.cs (RegisterBundles method)
.... other bundles ...
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
... other bundles ...
_Layout.cshtml*
... other head stuff ...
#Styles.Render("~/Content/css") <--- this name is the "virtual path" to that bundle of styles
... other head stuff ...
You define the bundles in BundleConfig.cs, which gets called from your Global.asax.cs.ApplicationStart() method:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
ViewEngineConfig.RegisterEngines(ViewEngines.Engines);
}
This should all be setup in the older template startup project.

static resources are not loaded for an application deployed on weblogic12c

I deployed a web application on WebLogic 12c (12.1.3) and when I hitting the login page, I get a HTTP-200 response for the login.html but the js and css files which are included in the login.html, not getting loaded and throwing HTTP-404 error.
Like below js is included in html
<script language="JavaScript" type="text/javascript" src="/resources/js/validation.js"/>
For validation.js getting http 404 error.
The resources folder is already under the application home directory.
I am new to weblogic.
Let me know if any configurations are required to set to get these js-files loaded whenever required for an application.
I am able to get the static contents after adding dot (.) in the src attribute like below
script language="JavaScript" type="text/javascript" src="./resources/js/validation.js" />

ASP.NET page is not loading CSS styles on my local iis web server

I have a local ASP.NET web site written in VB.NET runing on W7.
The default web page contains a simple style sheet which is loaded as follows
<link rel="stylesheet" href="dchs.css" type="text/css" media="screen" runat="server"></link>
The page is displayed without the above styling. The style sheet does exist as I can display it via the web browers as
file:///c:/inetpub/wwwroot/c1/dchs.css
but I cannot display it via the brower using
http://localhost/c1/dchs.css
This leads me to believe that IIS has some form of access problem to the C1 directory. It a similar way I can display a jpeg image via file://c1 bit not via localhost which gives an error message
The image "http://localhost/c1/menu.jpeg" cannot be displayed, because it contains errors.
How you attached the .css file to your html project? where is it located?
Options:
1. Drag and drop your .css file to your html page.(Inside)
like this:
<link rel="Shortcut Icon" href="images/fil.ico" />
Make sure all folders and files are include when project deployed And a correct calling of id or class in your css of course.

How can I get site's favicon using Selenium

I need to get web site's favicon.
How can I do that?
You won't be able to get the favicon with Selenium you would have to use another program to grab it. The only way you would be able to get it is if your website rendered the favicon.ico as a link such as
<link rel="shortcut icon"
href="http://example.com/myicon.ico" />
However typically websites just store the favicon.ico in the root directory and on page request the browser retrieves it and drops it in the address bar or tab or wherever favicons are used. If this is how your favicon is rendered then there will be no code or anything to search for with Selenium.
Also the above code while it does work has some buggy support for IE7.
You don't need Selenium.
Just request the site's home page and use an HTML parser to find a <link rel="shortcut icon" href="..."> tag.
If you don't find any such tag, try /favicon.ico.
Here is a bit crazy but working solution:
get the favicon image opened in a web page (and hence reachable with selenium) with the help of "http://www.google.com/s2/favicons". There are other services which provide a similar functionality, see:
Get website's favicon with JS
use cssneedle package to compare the resulting favicon with a pre-saved one
Needle is a tool for testing your CSS with Selenium and nose.
It checks that CSS renders correctly by taking screenshots of portions
of a website and comparing them against known good screenshots. It
also provides tools for testing calculated CSS values and the position
of HTML elements.
In other words, we are going to compare favicon images.
Example implementation (python):
from needle.cases import NeedleTestCase
class FavIconTestCase(NeedleTestCase):
def test_so(self):
self.driver.get('http://www.google.com/s2/favicons?domain=www.stackoverflow.com')
self.assertScreenshot('img', 'so-favicon')