uma
uma

Reputation: 1

How to close MVC C# application from Controller?

I want to close or exit the application or page completely. Using asp.net c# in MVC application controller

I tried below code but its not working.

public ActionResult SubmitForm()
{
    return View("Close");
}

<body>
    <script type="text/javascript">window.close();</script>
</body>

public ActionResult SubmitForm()
{
    return JavaScript("window.close();");
}

Upvotes: 0

Views: 1793

Answers (1)

Travis Acton
Travis Acton

Reputation: 4430

Per your requirements: Closing the page from the controller.

From a web platform not possible, the context of the request is running server side when you are in controller logic, not client side. Your only option is to return the request and try to close the browser client side via JS. Even then any js magic you do to close client browser will be hacky, browser dependent, and a nightmare to support in a production environment as the client itself should have control over applications run on their machine (ie the browser) and not the product that the browser is consuming. (and yes with the exception of browser windows that are spawned from your own code (via js) as it will/should have the ability to command over those instances.

Upvotes: 1

Related Questions