Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Web service in .NET project is initially unavailable unless anonymous access is granted.

Posted on 2010-09-15
Medium Priority
Last Modified: 2012-06-27
I have an ASP.NET application developed in Visual Studio 2008 with and JavaScript.
In this app I have a master page with a link on it that when clicked calls a JavaScript function named YourAre().  This function calls a web service named HelpService that returns a string of HTML.

The problem is that if the user clicks on the link when first entering the app they will get an error message that says,
"Line: 54 Error: 'HelpService' is undefined"

If they navigate to another page or even refresh the page they don't get the error.  If I give anonymous access to the web service by putting the following in the web.config file the error not longer occurs.
       <location path="WebServices/HelpService.asmx">
                        <allow users="?" />
This happens on both my development machine and the production machine.  This is an internal app and we use IE7 and 8, it happens with both.  I've attached the HTML and JavaScript for the master page and the VB for the web service.  Line 64 is the code for the link and line 112 is where the web service is called and the source of the error.  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" "">

<html xmlns="">
<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="/WebApps/ClientTrack3Point5/js/jquery/jquery-1.4.2.js" type="text/javascript"></script>    
    <script src="/WebApps/ClientTrack3Point5/js/jquery/jquery-1.4.2-vsdoc.js" type="text/javascript"></script>
    <script src="/WebApps/ClientTrack3Point5/js/jquery/jQueryUI.js" type="text/javascript"></script>
    <script src="/WebApps/ClientTrack3Point5/js/Master.js" type="text/javascript"></script>
    <script type="text/javascript">
        window.onbeforeunload = confirmExit;
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
                <asp:ServiceReference Path="~/WebServices/HelpService.asmx" />
        <div id="divPageWrapper">
            <div id="divHeaderOne">
                <asp:Image runat="server" ID="HeaderImage" CssClass="HeaderOneImage" ImageUrl="~/Images/MasterHeader.gif"
                    AlternateText="Logo" />
            <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" />
                    <DynamicMenuStyle CssClass="DynamicMenuStyle" />
                    <DynamicMenuItemStyle CssClass="DynamicMenuItemStyle" />
                    <DynamicHoverStyle CssClass="DynamicHoverStyle" />
            <div id="divHeaderTwo">
                <asp:Label ID="lblFormTitle" runat="server" Text="FormTitle"></asp:Label>
            <div id="divHeaderThree">
                <asp:UpdatePanel ID="UpdatePanelDDL" runat="server">
                        Records For
                        <asp:DropDownList ID="ddlRecordsFor" runat="server" Width="150px" CssClass="RecordsFor" AutoPostBack="True">
            <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">
                        <div class="Progress">
                        <br />
                        <div class="PleaseWait"> Please Wait...</div>
            <div id="divMainContent">
                <asp:ContentPlaceHolder ID="cp1" runat="server">
                    Under Construction
            <div id="divFooter">
                <asp:UpdatePanel ID="UpdatePanelButton" runat="server">
                        <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" />
        <div id="divHelp" visible="false"></div>
        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="False" />

var Message = "";
var MessageTitle;
function YouAre() {

    if (MessageTitle == "You Are") 
    else {
            $get("ctl00_UpdateProgressButton").style.display = "block";
            $get("ctl00_UpdateProgressButton").style.visibility = "visible";
                var t = setTimeout("SetHelpDialog()", 2000);
                if (e.description == "'HelpService' is undefined") 
                    alert("'HelpService' is undefined");
                    alert("Exception = " + e.number + " " + e.description);

function YouAreCallBack(result) 
    if (result.substring(0,5) == "Error")
        divHelp.title = result.substring(0, 5);
        MessageTitle = "Error";
        divHelp.title = "You Are";
        MessageTitle = "You Are";
        Message = result;

function SetHelpDialog() 
    divHelp.innerHTML = Message;
        height: "auto",
        modal: true,
        overlay: { background: '#fff', opacity: '0.7'}

    $get("ctl00_UpdateProgressButton").style.display = "none";

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
<System.Web.Script.Services.ScriptService()> _
    <WebService(Namespace:="")> _
    <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Public Class HelpService
    Inherits System.Web.Services.WebService

    <WebMethod(EnableSession:=True)> _
    Public Function YouAre() As String
        'Dim CurrentUser As New User("088316", "Group1|Group2")
        'Dim CurrentUser As New User("109537")
        'Dim CurrentUser As New User("065168")
        Dim CurrentUser As User = System.Web.HttpContext.Current.Session("CurrentUser")
            With CurrentUser
                Dim Title As String
                If .Title = "" Then
                    Title = "You have no title listed in Ultipro. To see more information on this topic click <a onclick=""DownLoadFile('http://Intranet/WebApps/ClientTrack3Point5/Help/ClientTrackManual.pdf#ProgInfGeneral')"">here.</a>"
                    Title = .Title
                End If

                Dim JobDescription As String
                If .JobDescription = "" Then
                    JobDescription = "You have no Job Description listed in Ultipro. To see more information on this topic click <a onclick=""DownLoadFile('http://Intranet/WebApps/ClientTrack3Point5/Help/ClientTrackManual.pdf#ProgInfGeneral')"">here.</a>"
                    JobDescription = .JobDescription
                End If

                Dim Supervisor As String
                If .Supervisor = "" Then
                    Supervisor = "You have no Supervisor listed in Ultipro."
                    Supervisor = .Supervisor
                End If

                Dim Programs As String
                If .Programs = "" Then
                    Programs = "There are no programs on the Program Information page for which you are listed as a staff. To see more information on this topic click <a onclick=""DownLoadFile('http://Intranet/WebApps/ClientTrack3Point5/Help/ClientTrackManual.pdf#ProgInfGeneral')"">here.</a>"

                    Programs = .Programs
                End If

                Dim Groups As String
                If .Groups = "" Then
                    Groups = "You are in no Active Directory Groups. To see more information on this topic click <a onclick=""DownLoadFile('http://Intranet/WebApps/ClientTrack3Point5/Help/ClientTrackManual.pdf#ProgInfGeneral')"">here.</a>"

                    Groups = .Groups
                End If
                Return String.Format("<u>YOU ARE:</u><br />{0} {1}<br /><br />" _
                                     & "<u>YOUR LOGIN NAME IS:</u><br />{2}<br /><br />" _
                                     & "<u>YOUR TITLE IS:</u><br />" & Title & "<br /><br />" _
                                     & "<u>YOUR JOB DESCRIPTION IS:</u><br />" & JobDescription & "<br /><br />" _
                                     & "<u>YOUR SUPERVISOR IS:</u><br />" _
                                     & "(If incorrect click " & "<a onclick=""DownLoadFile('http://Intranet/WebApps/ClientTrack3Point5/Help/ClientTrackManual.pdf#ProgInfGeneral')"">here.</a>)<br />" _
                                     & "{5}<br /><br />" _
                                     & "<u>THE PROGRAM(S) YOU ARE A {6} FOR ARE:</u><br /><div >" & Programs & "</div><br />" _
                                     & "<u>THE GROUPS YOU ARE IN ARE:</u><br /><div >" & Groups & "</div><br /><br />", _
                                     .FirstName, .LastName, _
                                     .UserName, _
                                     .Title, _
                                     .JobDescription, _
                                     .Supervisor, _
                                     .Title.ToUpper, _
                                     .Programs, _
            End With
        Catch ex As Exception
            Return "Error<br />The following error has occurred in the You Are function of the Help Service Web Service<br /><br />'" & ex.Message & "'<br /><br />Copy and paste this message into an e-mail to the IT help desk or call the IT help desk and read this exact message to them."
        End Try
    End Function

End Class

Open in new window

Question by:leskelly
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Author Comment

ID: 33684412
I've re posted this question and restated it to more clearly reflect the problem.

Author Comment

ID: 33684422
Ignore that last post as it was supposed to be for another question.

Expert Comment

ID: 33685026
I think there is no need of script manager to call a webservice.

please check if it helps:

Accepted Solution

leskelly earned 0 total points
ID: 33685290
Hello and thanks for your comment.  Are you saying you think the use of the script manager is the source of my problem?  If that were the case I would think the error would occur every time the web service was called and not just if it was called on the initial unrefreshed page.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API ( has made its way into the popular lexicon of the English language.  A few years ago, …
Online collaboration is quickly becoming embedded in the workplace, and its benefits are tangible. See what the current landscape looks like and what the future holds for collaboration tools and the future of work.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
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)

721 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