0

I am going to ask the dumnest question ever. I am creating a C# ASP.Net MVC4 application. I want a button on the index page that will shut the application down and close the browser. How do I do it? I currently have the following code snippet in my Index.cshtml to give a button:

@using (Html.BeginForm("CloseApplication", "Home", FormMethod.Post))
{
    <input id="close" name="closeButton" type="submit" style="width:170px" value="Close Application" />
}

I am going to a CloseApplication ActionResult method in my HomeController.cs which currently looks like:

public ViewResult    CloseApplication()
{
    // Something to do here I think
    return null;
}

What do I do here?

Am I over complicating things?

Many thanks to all of you who contribute regularly and help us out.

2
  • what do you mean by shut the application down and close the browser?! you can close the browser by using javascript easily, not requiring a postback to the controller. but what do you mean shut the application down?! Commented Nov 27, 2013 at 11:17
  • By that I mean closing any database connections which is normally done by the Dispose function in the HomeController. If javascript will easily close the browser, may I have a little code snippet please and where to put it? New to all this. Thank you. Commented Nov 27, 2013 at 11:27

1 Answer 1

2

Honestly think you are over-complicating things for yourself.

HTTP is stateless so by the time you have rendered a page onto the client's browser, your connections, etc, should have already been Dispose'd and the instance of the controller that returned the view the client is now looking at should no longer exist. The next request the client makes will spin up a whole other controller instance.

So the user can already "close" their "instance" (from their perspective) of the application by closing their browser - adding a button to do this is kind of pointless IMHO!

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I think I will stop using a "Close" button for this then.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.