Search code examples
javascriptasp.netajaxvb.netwebmethod

Is there a way to stop web methods from working when the project stops running in .NET?


I'm working on an application which has to use VB.NET on server side. Basically, I'm calling WebMethods from JavaScript using AJAX. (More precisely, JQuery's AJAX function)

While it's all good and I have no problem receiving and uploading data, there's something that is still bothering me.

Even after I stop the project from running, I still retain all the functionality from the WebMethods on client side. In fact, I can stop the project from running, then press 'Add to Cart' client side which calls a WebMethod that adds some records into a database. If I then check my database, the new records are there, even though the project was not running.

I figured I could at least check to see if the session was alive in order to prevent this from happening but to no avail. Does anyone have any idea what could be causing this behavior?

Here's how I'm checking to see if the session is still alive:

<WebMethod()> Public Shared Function AddToCart(ByVal itemCode As String, ByVal company As String) As String
    If (HttpContext.Current.Session("spusrid") IsNot Nothing) Then
        '//Its all good keep going!
    Else
        Return "ERROR-20"

    End If

    '//Remainder of code which adds Item to cart.

End If

If it helps at all, I'm running the project locally. I'm just worried the behavior will carry on to the live site.


Solution

  • My guess is that Visual Studio has fired up the project in IIS Express. If that's the case, it should show up in your system tray and you can kill that specific site. An alternative is to close the project in Visual Studio, and that will stop the site from running as well.