Does IIS have to be configured to run WebMethods?

Easierthanyou 1 Reputation point
2022-12-30T15:57:17.313+00:00

I have this code:

<script type="text/javascript">
window.onbeforeunload = function (e) {
PageMethods.LogOutOfRecord();
};
</script>

[WebMethod(EnableSession = true)]
public static void LogOutOfRecord()
{
ApplicantEntryEdit aee = new ApplicantEntryEdit();
aee.LoggingOutOfInvestigation();
}

This code works great locally in Visual Studio. However the WebMethod does not get hit on IIS on testing server.

Thanks in advance!

Internet Information Services
{count} votes

3 answers

Sort by: Most helpful
  1. TechLife 246 Reputation points
    2023-01-01T15:47:11.137+00:00

    To use PageMethods, you will need to make sure that you have enabled the following:

    1. EnableSession attribute on the WebMethod
    2. ScriptManager control on the page
    3. EnablePageMethods property on the ScriptManager control

    Here's an example of how you can set this up:

    <asp:ScriptManager runat="server" EnablePageMethods="true" />  
      
    [WebMethod(EnableSession = true)]  
    public static void LogOutOfRecord()  
    {  
        ApplicantEntryEdit aee = new ApplicantEntryEdit();  
        aee.LoggingOutOfInvestigation();  
    }  
      
    

    Additionally, make sure that the WebMethod is being called from the correct URL. You can check this by inspecting the network traffic in your browser's developer tools and seeing if the WebMethod is being called and if it is returning a response.


  2. Sam Wu-MSFT 7,036 Reputation points Microsoft Vendor
    2023-01-02T02:23:46.607+00:00

    @Easierthanyou

    You can try removing router settings in web.config and adding to httpmodules section.

    <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>  
    

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  3. Easierthanyou 1 Reputation point
    2023-01-11T21:35:31.7466667+00:00
    The below code works on the server.
    
    The above code does not.
    
    This was the issue.
    
    

    window.addEventListener('beforeunload', (event) => { PageMethods.LogOutOfRecord(); });

    I do not have an explanation as to why the original code will work locally and not on the server and this one will work on both.
    
    0 comments No comments