gruff
gruff

Reputation: 411

ASP .NET On_Load method not executing

I am working on a kludge which is working locally but not after I deploy it to our server.

I have a web page which opens, runs an EXE and then closes the web page. Locally this works but after publishing to the server the EXE does not run. I have confirmed that the file path works from the server.

My Web Page code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EmailSignature_EXEC.aspx.cs" Inherits="_Default" %>

<html>
<head>
    <title></title>
<script>
function loaded()
{
    window.setTimeout(CloseMe, 500);
}

function CloseMe() 
{
    window.open('', '_self').close();
}
</script>
<script type="text/javascript">
</script>
</head>
<body onLoad="loaded()">
Hello!
    \\\\cmbfs02\\Software\\web\\EmailSignature_WPF\\EmailSignature_WPF.exe
</body>
</html>

C# Code:

using System.Diagnostics;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load()
    {
        var applicationPath = "\\\\cmbfs02\\Software\\web\\EmailSignature_WPF\\EmailSignature_WPF.exe";
        Process.Start(applicationPath);
        this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "window.close()", true);
    }
}

When I browse to my page on IIS I see the page appear and close after the Timeout but the Application doesn't run. If I copy the EXE path into Windows Explorer the application runs, but it does not from the method. Any help appreciated

Upvotes: 1

Views: 274

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1063338

It sounds like you're trying to launch a UI exe on the client, but what you're actually doing is executing it on the web server. If that's right, then fundamentally what you're trying to do is just ... not going to work. Ignoring the fact that the implementation would have to be completely different, browsers are explicitly designed not to run arbitrary executables from web servers - plus of course it would only work on certain OSes - presumably windows in this case.

A few years ago I might have said "look into ClickOnce for this" - but I have no idea whether that option is still supported or recommended.

Upvotes: 1

Related Questions