I'm trying to retrieve the ID of an employee and show them in my details page by retrieving the Employee ID from the URL using Page Mapping in ASP.NET:
RouteTable.Routes.MapPageRoute("", "employee/{id}", "~/details.aspx");
Such that the URL will be:
www.myexamplewebsite.com/employee/7937822353
The problem is, the Javascript files don't get loaded and the console is full of my javascript errors. I get a 404 error in my JS scrips as well. The page can't find any JS file when mapped. Why is this happening when I map the URL? This does not happen if the URL is www.myexamplewebsite.com/7937822353.
What am I doing wrong?
EDIT:
This is how my JS files are referenced:
<script src="js/chatbar/rightside.js"> </script>
The script is relative, and it's from the perspective of the client side URL. So when you change the page route to have the page appear to be served from a /employee subdirectory, the correct relative path to your scripts changes. So it's looking for the scripts at /employee/js/charbar/rightside.js. You could change those relative paths (to something like ../js/chartbar/rightside.js), but you might run into a problem later if you change the routing again.
So instead, it's best to make the reference application root relative.
<script src='<%= ResolveClientUrl("~/js/chatbar/rightside.js")%>'></script>
Related
I subscribe to a service that lets me do custom order forms on my ecommerce site. They do this by embedding a javascript file on my page, like this:
<script type="text/javascript" src="https://example.com/file.js?ofid=27275"></script>
Then I can go into their site and do the cusomizations, which will appear on my order form. If I try to view the js file directly, I get an error 400. But it's obviously working properly on my site...
Is there any way to view the file contents? I'd just like to verify there's nothing shady in there...
I am trying to achieve the below in ASP.NET MVC3 web application which uses razor.
1) In my Index.cshtml file, I have the below reference.
<script src="/MySite/Scripts/Main.js"></script>
2) I load my home page for the first time and a http request is made to fetch this file which returns 200.
3) Then, I made some changes to the Main.js and saved it.
4) Now I just reload the home page (please note that I am not refreshing the page) by going to the address bar and typing the home page url and pressing enter. At this point, I want the browser to fetch the updated Main.js file by making a http request again.
How can I achieve this? I don't want to use System.Web.Optimization bundling way. I knew that we can achieve this by changing the URL (appending version or some random number) everytime the file changes.
But the challenge here is the URL is hardcoded in my Index.cshtml file. Everytime when there is a change in Main.js file, how can I change that hardcoded URL in the Index.cshtml file?
Thanks,
Sathya.
What I was trying to achieve is to invalidate browser cache as soon as my application javascript file (which already got cached in the browser) gets modified at the physical location. I understood that this is simply not achievable as no browsers are providing that support currently. To get around this below are the only two ways:
1)Use MVC bundling
2)Everytime the file is modified, modify the URL by just appending the version or any random number to the URL through querystring. This method is explained in the following URL - force browsers to get latest js and css files in asp.net application
But the disadvantage with the 2nd method is, if there are any external applications referring to your application's javascript file, the browser cache will still not be invalidated without refreshing the external application in browser.
Just add a timestamp as a querystring parameter:
var timestamp = System.DateTime.Now.ToString("yyyyMMddHHmmssfff");
<script src="/MySite/Scripts/Main.js?TimeStamp=#timestamp"></script>
Note: Only update TimeStamp parameter value, when the file is updated/modified.
It's not possible without either using bundling (which internally handles version) or manually appending version. You can create a single file bundle as well if you want.
When working on a handlebars demo, I am noticing that the stylesheet does not show up when viewing the page. I have provided links to the code and the live page below. Does anyone know why the stylesheet isn't working?
The code is here:
https://github.com/sutri001/DA670/tree/master/week7_handlebars
The live page is here:
http://67.205.184.187:1000
Your rendered page does have the link tag that references the stylesheet you're looking for. What's happening is your server is throwing a 404 when a request is made for the stylesheet.
Looking at the code for your express server, I see you're telling express to serve files staticly from the public directory (good)... but you don't have a public directory, and even more your css directory is located outside of such a place.
My advice is to move your css directory into a new public directory (so you'll have public/css/style.css). That should resolve your issue.
Also, remember that it's the browser that's handling your link tags, not the server! That means browsers are currently trying to go to http://yoursite/../../css/style.css. Thankfully your browser understands how to handle this, but this is definitely not what you want.
Your link tag's href attribute should be set to /css/style.css because, from the browser's perspective, that's where the stylesheet is located.
I have a web page that has an iFrame in it with a definition in the HTML like the following:
<iframe id="page_is_fresh" src="~/HTML/fresh.html" style="display: none"></iframe>
My site is running under a subfolder /Marketing so all urls are something like http://myserver/Marketing/SomeFolder/someitem.html
I have javascript to change the src of my iframe when an item on the form changes.
$('#page_is_fresh').attr('src', '/HTML/stale.html');
The problem is, this makes the url http://myserver/HTML/stale.html
I tried using '~/HTML/stale.html' and that gives me http://myserver/Marketing/SomeFolder/~/HTML/stale.html which doesn't work either.
How can I get it to give me http://myserver/Marketing/HTML/stale.html without having to hard code the /Marketing part in?
Use ../HTML/stale.html instead of ~/HTML/stale.html or /HTML/stale.html in your javascript.
The server considers ~ to be a directory in the way you formatted it.
../ lets the server know it needs to start one directory up
I am having a problem in the location of my javascript, the location is right, but when I run it in my visual web developer 2010 express, the location can not be found, I don't know the reason why...
here is the location of my javascript:
<script src="Style/javascript/jquery-1.7.1.js" type="text/javascript"></script>
here is the error:
**Server Error in '/Maitenance' Application.**
**The resource cannot be found.**
**Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.**
**Requested URL: /Maitenance/Maintenance/Style/javascript/jquery-1.7.1.js**
Use this... It will work
<script src="<%=Page.ResolveUrl("~")%>Style/javascript/jquery-1.7.1.js" type="text/javascript"</script>
I guess you are using a master page and your .aspx page is put in another directory. The file path you included in master page is relative to the .aspx file. It works OK when your page in the same directory with the master page.
You can include your js file using ResolveUrl:
<script src="<%=ResolveUrl("~/js/jquery.js")%>" type="text/javascript"></script>
or you can include your script in the code behind of master page:
ClientScript.RegisterClientScriptInclude("jquery", ResolveClientUrl("~/js/jquery.js"));