1

I am writing a tiny MVC app that is a utility to simulate the actions of getting an id from a portal and setting it in a database for another app to obtain while this app is open. I attempted to write it using ASP.NET MVC to "get my feet wet." In it, I am attempting to use the JavaScriptResult (DESPITE all the warnings) to execute Javascript's window.open function but I get only a file dialog that is acting like the FilePathResult - it displays a dialog box asking if I want to save my file which is the name of the ActionEResult. How do I do this?

public JavaScriptResult SessionTransferDesktop(string PortalUserId)
{
    /// .... Call Oracle SP to set token

    // Redirect to RON Scheduler
    string js = "window.open('/RONSchedulerMVC/default.aspx?p_token=' + portalToken);";
    // string js ="window.open('http://microsoft.com')";
    return JavaScript(js);
}
Sam Gentile
  • 1,259
  • 7
  • 22
  • 28

2 Answers2

1
public ActionResult SessionTransferDesktop(string PortalUserId)
{
    /// .... Call Oracle SP to set token

    // build url and redirect
    var uriBuilder = new UriBuilder("http://example.com");
    uriBuilder.Path = "/RONSchedulerMVC/default.aspx";
    uriBuilder.Query = "p_token=" + Url.Encode(portalToken);
    return Redirect(uriBuilder.ToString());
}
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • This is getting to the application which is running in Cassini and producing "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS." – Sam Gentile Nov 04 '10 at 13:19
  • The other guy switched over the app to IIS but we can't get the default.aspx to run there. – Sam Gentile Nov 04 '10 at 13:29
  • HttpContext.Current.RewritePath(Request.ApplicationPath, false); IHttpHandler httpHandler = new MvcHttpHandler(); httpHandler.ProcessRequest(HttpContext.Current); – Sam Gentile Nov 04 '10 at 13:29
  • It is IIS 5.1 we have. Does MVC run on IIS 5.1? – Sam Gentile Nov 04 '10 at 13:30
  • HttpContext.Current.RewritePath(Request.ApplicationPath, false); is "/" in Casini and "/RonSchedulerMVC/" in IIS but we can't get it to run in IIS 5.1 – Sam Gentile Nov 04 '10 at 13:34
  • I see this thread http://stackoverflow.com/questions/301359/deploy-asp-net-mvc-on-iis-5-1-windows-xp – Sam Gentile Nov 04 '10 at 13:37
0

You are getting the file result because your browser is requesting something and getting content-type:application/javascript back.

The easiest way to get this to work is to simply make the route redirect the response to the portal. You can then just call window.open directly on said route and profit.

Wyatt Barnett
  • 15,573
  • 3
  • 34
  • 53