hrshd
hrshd

Reputation: 1001

How to direct to an .aspx web form from a controller (MVC 5 framework)?

I have a MVC project which needs to incorporate SSRS reports as a part of the application. I've not done this before so I read up a couple of blogs, msdn pages etc. But I haven't come across a concrete solution yet.

Here's my code for the controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AppName.Controllers
{
    public class ReportsController : Controller
    {
    //
    // GET: /Reports/
    public ActionResult Index()
    {
        var reportParameters = new Dictionary<string, string>();


        reportParameters.Add("First_Name", "TEST");

        Session["reportParameters"] = reportParameters;

        return Redirect("../Views/Reports/Index.aspx");
    }
}
}

The last line 'return Redirect' does not redirect to the desired page , instead it gives me a 'can't find the page' error and the link displayed is as follows:

"/localhost:port#/Error/PageNotFound?aspxerrorpath=/Views/Reports/Index.aspx"

I have even tried 'RedirectRoute' and 'RedirectToAction', but none of them work. I am using a web form instead of an MVC view because that's what is presribed by many SSRS tutorials in order to achieve what I want. I know the redirect line has worked in the past for most folks. I'm surely missing something here. Any help would be greatly appreciated!

Thanks, H

Upvotes: 1

Views: 4588

Answers (1)

JotaBe
JotaBe

Reputation: 39004

There is just a little tweak to have it working: instead of using a relative URL, do use an URL relative to the application root ~, like this:

return Redirect("~/Views/Reports/Index.aspx");

This will generate the current redirect URL.

EDIT

There can be a second problem in this case. The Views folder is somewhat special, because it has its own web.config which can make it impossible to get the files inside it. So you also need to move your .aspx page to somewhere else and update the Redirect accordingly.

To be more precise, if you look inside the web.config of your Views folder you'll find this:

<system.web>
  <httpHandlers>
    <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
  </httpHandlers>

which means that any request to this folder will be handled with the HttpNotFoundHandler, thus you'll get the "not found" message.

Upvotes: 4

Related Questions