Solved

Reference to javascript file in master page not found

Posted on 2010-08-12
12
490 Views
Last Modified: 2013-11-26
I have a master page in a .NET application which was developed in Visual Studio 2008 and which has references to 4 javascript files.  The references were created when I dragged and drop the files from the Solution Explorer into the header of the master page.  There is also a reference to a javascript file in the header content place holder of a page based on the master page.  There are no warnings regarding either page in the error list.but when I run the application and open the page an error is thrown for each reference that looks like this:
Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6.5; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.0.3705; InfoPath.2; MS-RTC EA 2)
Timestamp: Thu, 12 Aug 2010 14:41:41 UTC

Message: Syntax error
Line: 3
Char: 1
Code: 0
URI: http://localhost:1846/login.aspx?ReturnUrl=%2fjs%2fLogin.js

Message: Syntax error
Line: 3
Char: 1
Code: 0
URI: http://localhost:1846/login.aspx?ReturnUrl=%2fjs%2fjquery%2fjquery-1.4.2.js

Message: Syntax error
Line: 3
Char: 1
Code: 0
URI: http://localhost:1846/login.aspx?ReturnUrl=%2fjs%2fjquery%2fjquery-1.4.2-vsdoc.js

Message: Syntax error
Line: 3
Char: 1
Code: 0
URI: http://localhost:1846/login.aspx?ReturnUrl=%2fjs%2fjquery%2fjQueryUI.js

Message: Syntax error
Line: 3
Char: 1
Code: 0
URI: http://localhost:1846/login.aspx?ReturnUrl=%2fjs%2fMaster.js

I've attached the code for the master and content pages.  Any assistance would be greatly appreciated.
<%@ Master Language="VB" CodeFile="ClientTrack.master.vb" Inherits="ClientTrack" %>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>Site Master Page</title>

    <asp:ContentPlaceHolder id="head" runat="server"></asp:ContentPlaceHolder>

   

    <link href="/Styles/Master.css" rel="stylesheet" type="text/css" />

    <link href="/Styles/Dialog.css" rel="stylesheet" type="text/css" />



    <script src="../js/jquery/jquery-1.4.2.js" type="text/javascript"></script>    

    <script src="../js/jquery/jquery-1.4.2-vsdoc.js" type="text/javascript"></script>

    <script src="../js/jquery/jQueryUI.js" type="text/javascript"></script>

    <script src="../js/Master.js" type="text/javascript"></script>   

    

    <script type="text/javascript">

        window.onbeforeunload = confirmExit();

    </script>

    

</head>

<body>

    <form id="form1" runat="server">

        <asp:ScriptManager ID="ScriptManager1" runat="server">

            <Services>

                <asp:ServiceReference Path="~/WebServices/HelpService.asmx" />

            </Services>

        </asp:ScriptManager>

        <div id="divPageWrapper">

            <div id="divHeaderOne">

                <asp:Image runat="server" ID="HeaderImage" CssClass="HeaderOneImage" ImageUrl="~/Images/MasterHeader.gif"

                    AlternateText="Logo" />

            </div>

            <div id="divMenu">

                <asp:Menu CssClass="MainMenu" ID="MasterMenu" runat="server" DataSourceID="SiteMapDataSource1"

                    Orientation="Horizontal" StaticEnableDefaultPopOutImage="False">

                    <StaticSelectedStyle CssClass="StaticSelectedStyle" />

                    <StaticMenuItemStyle CssClass="StaticMenuItemStyle" ItemSpacing="0px" />

                    <StaticHoverStyle CssClass="StaticHoverStyle" />

                    <DynamicHoverStyle CssClass="DynamicHoverStyle" />

                    <DynamicMenuItemStyle CssClass="DynamicMenuItemStyle" />

                </asp:Menu>

            </div>

            <div id="divHeaderTwo">

                <asp:Label ID="lblFormTitle" runat="server" Text="FormTitle"></asp:Label>

            </div>

            <div id="divHeaderThree">

                <asp:UpdatePanel ID="UpdatePanelDDL" runat="server">

                    <ContentTemplate>

                        Records For

                        <asp:DropDownList ID="ddlRecordsFor" runat="server" Width="150px" CssClass="RecordsFor" AutoPostBack="True">

                            <asp:ListItem>1</asp:ListItem>

                            <asp:ListItem>2</asp:ListItem>

                            <asp:ListItem>3</asp:ListItem>

                        </asp:DropDownList>

                    </ContentTemplate>

                </asp:UpdatePanel>

            </div>

            <div id="divSideBar">

                <asp:LinkButton ID="LogOff" runat="server">Log Off</asp:LinkButton>

                <a id="SpellCheck" onclick="checkspell()">Spell Check</a><br />

                <a id="YouAre" onclick="YouAre()">You Are</a>

                <asp:HyperLink ID="YouCan" runat="server">You Can</asp:HyperLink>

                <asp:HyperLink ID="WhoCan" runat="server">Who Can</asp:HyperLink>

                <asp:HyperLink ID="HowCan" runat="server">How Can</asp:HyperLink>

                <asp:UpdateProgress ID="UpdateProgressButton" runat="server">

                    <ProgressTemplate>

                        <div class="Progress">

                        </div>

                        <br />

                        <div class="PleaseWait"> Please Wait...</div>

                    </ProgressTemplate>

                </asp:UpdateProgress>

            </div>

            <div id="divMainContent">

                <asp:ContentPlaceHolder ID="cp1" runat="server">

                    Under Construction

                </asp:ContentPlaceHolder>

            </div>

            <div id="divFooter">

                <asp:UpdatePanel ID="UpdatePanelButton" runat="server">

                    <ContentTemplate>

                        <asp:Button ID="btnDivideByZero" runat="server" Text="Divide by Zero" Width="125px" />

                        <asp:Button ID="btnPageNotFound" runat="server" Text="Page Not Found" Width="133px" />

                        <asp:Button ID="btnDatabaseError" runat="server" Text="Data base Error" Width="125px" />

                    </ContentTemplate>

                </asp:UpdatePanel>

            </div>

        </div>

        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="False" />

        <div id="divHelp"></div>

    </form>

</body>

</html>



<%@ Page Language="VB" MasterPageFile="~/MasterPages/ClientTrack.master" AutoEventWireup="false" CodeFile="Login.aspx.vb" Inherits="Login" Title="Login" %>



<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="Server">

    <script src="../js/Login.js" type="text/javascript"></script>

</asp:Content>



<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="cp1">



    <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">

        <Services>

            <asp:ServiceReference Path="~/WebServices/LoginService.asmx" />

        </Services>

    </asp:ScriptManagerProxy>



    <div id="divLogin" title="Login">

        <asp:Label ID="lblUserName" runat="server" Text="User Name:"></asp:Label>

        <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>

        <br />

        <asp:Label ID="lblPassWord" runat="server" Text="Pass Word:"></asp:Label>

        <asp:TextBox ID="txtPassWord" runat="server" TextMode="Password"></asp:TextBox>

        <br />

        <input id="btnLoginHtml" type="button" value="LoginHtml" onclick="Login(ctl00$cp1$txtUserName.value, ctl00$cp1$txtPassWord.value)" />

     <%--   <asp:Button ID="btnLogin" runat="server" Text="Login" />--%>

    </div>

</asp:Content>

Open in new window

0
Comment
Question by:leskelly
  • 8
  • 3
12 Comments
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
Nprmaly it do not have to change anything but remove all ".." at the beginning of your .js paths.
Like this:

    <script src="/js/jquery/jquery-1.4.2.js" type="text/javascript"></script>    
    <script src="/js/jquery/jquery-1.4.2-vsdoc.js" type="text/javascript"></script>
    <script src="/js/jquery/jQueryUI.js" type="text/javascript"></script>
    <script src="/js/Master.js" type="text/javascript"></script>  


Do not forget this one:
    <script src="/js/Login.js" type="text/javascript"></script>


Good luck!

0
 

Author Comment

by:leskelly
Comment Utility
Hello Zvonka,

Thanks for the suggestion but I'm afraid it didn't make any difference.  Any other ideas?
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
The check is simple: that what you expect to be accessible by the page as .js file has to be accessible for you also in the browser address bar.
That mean, enter this address in browser and check the existence of the file:

http://localhost:1846/js/jquery/jquery-1.4.2.js

If you get the 404 page not fount error then simply that file is not there.
Look on the web server directory at the root of all you pages and check what is wrong with the paths.

0
 

Author Comment

by:leskelly
Comment Utility
The files are definitely there as I had said I created the references by dragging them to the master page however I do get the 404 error.  This is most peculiar as I get it even if I try to open the file by going through the Directory listing.  In the attached file you can see that the jquery-1.4.2.js file shows up as a link in the directory listing but if I click on the link I get the 404 error.  This must be a permissions issue.


Doc1.doc
0
 

Author Comment

by:leskelly
Comment Utility
Actually I'm still unsure of the problem.  The login.aspx page is the start page for the project so when I tried to open any other file I got redirected to it.  I excluded it from the project thinking that would remove it as the start up page but it didn't so the 404 error was caused because the browser couldn't find the login page.
0
 

Author Comment

by:leskelly
Comment Utility
I would the location in Visual Studio to change the start options.  I tried leaving the start page blank then I tried setting it to the URL of one of the javascript files but if I try to browse to any file in the application I get redirected to the login page.  Still I know the file is there as the attached document from two post ago shows.  Do you have any other thoughts?
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
That localhost:1864 port is serving request only during that time when you start such an page in your development IDE.

Therefore either upload that project to a server or let the serving request open while you do the tests in browser.

I have to check how VisualStudio runs that stuff and will come back. You use VisulaStudio?, right?

0
 

Author Comment

by:leskelly
Comment Utility
Yes, I'm using Visual Studio 2008.
0
 
LVL 7

Accepted Solution

by:
jhp333 earned 500 total points
Comment Utility
It seems your server do not allow any file until the user logs in, and it's redirecting the js read requests to your login page, login.aspx.
You need to always allow *.js files.
0
 

Author Comment

by:leskelly
Comment Utility
Hello,

and thanks for your response.
How do you allow *.js files?

Right now I'm working on my development machine and using the Visual Studio Development Server.
0
 

Author Comment

by:leskelly
Comment Utility
As the user is not yet authenticated when on the log in page I had to allow anonymous access to the folder the Javascript files are in.  I did this by adding the code below to the web.config file.  I believe this is what  jhp333 was referring to above.
<location path="js">
    <system.web>
        <authorization>
            <allow users="?" />
        </authorization>
    </system.web>
</location>

Open in new window

0
 

Author Closing Comment

by:leskelly
Comment Utility
See my final comment.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now