JQuery function is not working after URL Rewriting - asp.net

Refer to my this question: Page not redirecting properly, URL rewriting (Asp.NET)
Which is resolved except one thing.
Though I have put the code to eliminate post back for .jpg and other file extension, JQuery at the web page is not working.
<script type="text/javascript" src="JS/jquery.js"></script>
I have written it like the above. I have tried to change the path like
<script type="text/javascript" src="~/JS/jquery.js"></script>
but no luck.
Any suggestion

Try this.
<script type="text/javascript" src= "<%=ResolveUrl("~/JS/jquery.js")%>" ></script>

you first check if the string contains /web/
if (app.Request.RawUrl.ToLower().Contains("/web/"))
and your .js file doesn't contain /web/
so either put the js file in the web folder, or check for the string to contain /js/ as well...
if (app.Request.RawUrl.ToLower().Contains("/web/") || if (app.Request.RawUrl.ToLower().Contains("/js/")))

Related

How to load geojson file in asp.net mvc

I have been adding the following files in my cshtml page.
<script src="http://code.highcharts.com/maps/highmaps.js" )"></script>
<script src="https://code.highcharts.com/maps/modules/data.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/offline-exporting.js"></script>
<script src="https://code.highcharts.com/maps/modules/drilldown.js"></script>
<script src="~/Content/js/balochistan.geojson"></script>
And the code for higmaps is present on the same page with script tag. Everything is working fine but hte map is not displaying and giving error for geojson file not being loaded.
http://localhost:9090/Content/js/balochistan.geojson net::ERR_ABORTED 404 (Not Found)
Can anyone please helpthat how a geojson file can be loaded properly and how to give static path to it correctly?
the file ends with .geojson can not be loaded like that - as script - because is a json file
Add this file is a set of json data - you need to loaded them on highcharts either with ajax load, either add them as variable at the beginning and connected to the chart.
Resolved:
The problem resolved by doing few steps like:
adding script tags in proper order.
secondly highmaps.js and highcharts.js file conflict with each other when used on the same page.
In order to resolve this issue you have to add
<script src="http://code.highcharts.com/highcharts-more.js"></script>
script tag in addition to highcharts.js and also replace the highmaps.js with:
<script src="//code.highcharts.com/maps/modules/map.js"></script>
like this:
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="//code.highcharts.com/maps/modules/map.js"></script>
This resolved my problem and map is showing now.

Problem with "~" in routing file instead of ".."

I'm working on a asp.net web-form website in which I use ../ for routing files like js files, styles, etc. When I decided to apply ScriptBundle and replace ~/ instead ../ the website didn't work at.
js file completely are loaded on browser but they didn't work.
This is my code before ScriptBundle that work perfectly:
<!-- Page Scripts Starts -->
<script src="../Script/jquery.min.js"></script>
<script src="../Script/jquery.colorpanel.js"></script>
<script src="../Script/bootstrap.min.js"></script>
<script src="../Script/jquery.flexslider.js"></script>
<script src="../Script/bootstrap-datepicker.js"></script>
<script src="../Script/owl.carousel.min.js"></script>
<script src="../Script/custom-navigation.js"></script>
<script src="../Script/custom-flex.js"></script>
<script src="../Script/custom-owl.js"></script>
<script src="../Script/custom-date-picker.js"></script>
<!-- Page Scripts Ends -->
and this is after ScriptBundle:
<!-- Page Scripts Starts -->
<%: Scripts.Render("~/Script/js") %>
<!-- Page Scripts Ends -->
Cs file:
bundles.Add(new ScriptBundle("~/Script/js").Include(
"~/Script/bootstrap-datepicker.js",
"~/Script/bootstrap.min.js",
"~/Script/custom-date-picker.js",
"~/Script/custom-flex.js",
"~/Script/custom-navigation.js",
"~/Script/custom-owl.js",
"~/Script/jquery.colorpanel.js",
"~/Script/jquery.flexslider.js",
"~/Script/jquery.min.js",
"~/Script/owl.carousel.min.js"));
That is beacuse the order of the script files (in .cs) is wrong. jquery.min.js should most likely be first. Change the order so that it is the same as per your working example. Since atleast all jquery.*.js files uses jquery.min.js they must be loaded after jquery.min.js.

How to use Icon8 webicons in static HTML?

I am trying to embed Icon8 SVG's in my code
This question relates to this website:
https://icons8.com/welovesvg
I linked to the CDN in the head:
<script type="text/javascript" src="//cdn.rawgit.com/icons8/bower-webicon/v0.10.7/angular-webicon.min.js"></script>
And I put this in the HTML:
<webicon icon="material:account-box"/>hello</webicon>
But nothing is showing up...how can I make this work?
They also say to link to their website, as I did.
The file on my URL is at:
http://xuzo.com/icon8.html

How to set the root path for asp.net application

I have an asp.net application containing pages that lie in multiple folder. I have my .js files also in one "JS" folder and I have added their reference in head of master page like:
<script type="text/javascript" src="JS/jquery.min.js"></script>
Now when I am on home page, the script loads fine. But when I am on some other page that is present in another folder(Physics for example), the path gets appended and hence I get the error:
Failed to load resource: the server responded with a status of 404
(Not Found)
Similar thing is happening for my image paths and <a> tags also.
Now I want to give paths with respect to root path something like:
~/JS/VerticalMenu.js
But this ~ is not taking me to the root of my application. Do I need to set where ~ should lead to? And if yes then where and how??
The #Charlie Kilian answer is a workable solution however you can also specify a base URL for all the relative URLs in your page by base tag in head of your html page.
<head>
<base href="http://www.yourdomain.com/anyvirtualdirectory/" />
</head>
Try this:
<script type="text/javascript"
src="<%=Page.ResolveUrl("~/JS/VerticalMenu.js")%>"></script>
If it's an ASP.NET application, you can access the root by prefixing the path ~/:
<script src="~/common/scripts/safeguard.common.js" type="text/javascript"></script>
You can also try prefixing the path with just /:
<script src="/common/scripts/safeguard.common.js" type="text/javascript"></script>

Base URL in ASP.net Master Pages with virtual Directories

I have an ASP.net master page. In this master, I have all my css and javascript files defined. I also have a few images and a few buttons and hyperlinks.
All the urls are all declared as relative ie "/scripts/ian.js"
Everything works fine if this site is the root website, but I need it to work in a virtual directory.
My problem is when I place this website in a virtual directory under a root site, all my links are pointing to the root site. so my links point to www.root.com/scripts/ian.js but it should be pointing to www.root.com/virtualDir/scripts/ian.js
I thought the Base Href tag in the header would help, but so far it does not seem to be helping in anyway. All the links are still pointing to the root website when i hover over them.
What I would like is a single setting either in IIS or the config file that I can set a root url and any image, script or link either on the master page or content page, would point to the right place.
Any suggestions or ideas are welcome.
Thanks
All the urls are all declared as
relative ie "/scripts/ian.js"
Those seem to be absolute URL's that you're using, rather than relative URL's, which is probably why the <base /> tag isn't having the desired effect:
This attribute specifies an absolute
URI that acts as the base URI for
resolving relative URIs.
-- from http://www.w3.org/TR/html401/struct/links.html#h-12.4
You could try removing the leading '/' from your URL's to see if that works?
Failing that, I tend to use ResolveClientUrl to get around issues like this, which you'd use in the same way as others have suggested using ResolveUrl:
<script type="text/javascript" src="<%= ResolveClientUrl("~/path/to/js") %>"></script>
...
<img src="<%= ResolveClientUrl("~/path/to/img") %>" alt="..." />
Hope this helps.
Most tags, including regular HTML tags like <link>, <img>, etc can use the ~/ as the application root path if the *'runat="server"' attribute is set.
eg.
<img src="~/images/test.png" runat="server" />
This makes tag a server tag and the tilde is replaced with the application root before the output is returned to the browser.
This doesn't work as expected for the <script> though. When 'runat="server' is set for the script tag, then the script is considered to be server-side javascript and execution is attempted.
To work around this you can either inject the javascript using one of the register client script methods. your you can use the <%= ResolveUrl('~')%> tag in your script tag.
This static method returns you full http path to root folder of your application (web site or virtual directory)
public static string GetAppRootUrl(bool endSlash)
{
string host = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);
string appRootUrl = HttpContext.Current.Request.ApplicationPath;
if (!appRootUrl.EndsWith("/")) //a virtual
{
appRootUrl += "/";
}
if (!endSlash)
{
appRootUrl = appRootUrl.Substring(0, appRootUrl.Length - 1);
}
return host + appRootUrl;
}
So, you can write in master page:
<script src="<%= Server.HtmlEncode(GetAppRootUrl(false)) %>/scripts/ian.js" language="javascript" type="text/javascript"></script>
Use tilde(~) in yout reference (i.e ~/scrips/ian.js)...see if it works
For links try Page.ResolveUrl in the .aspx page.
So I found this IIS weirdness last night:
<script src="/js/file.js"></script>
Will not work properly in a virtual application that's in a subdirectory of the main IIS site.
Instead, you MUST do it like this:
<script src="/js/file.js" type="text/javascript"></script>
Which is the standard way to do it, but if you're not looking for it, it can surprise you that that additional tag makes the relative path issues go away.

Resources