How to call a classic ASP.NET Page from a MVC Action? - asp.net

I am using StructureMap with ASP.NET MVC. I have a requirement where I need to show a ReportViewer and for that I am using a classic ASP.NET page. The problem is when I am trying to redirect from the action I am getting following issue:
The IControllerFactory 'StructureMapControllerFactory' did not return a controller for the name 'Reports.aspx'.
Can someone please guide me on how do I call a classic asp.net page from an action and get rid of this error?

You need to map a route for your classic page so that the MVC engine skips it.

If you are looking to redirect the request to a 'classic' ASP.NET web form from the controller action, you might call HttpContext.Response.Redirect("URL"). The routing engine by default will resolve files that exist on the disk. No need to map new routes.

Related

Remove ASP.NET MVC URL routing from project

This is a similar question to
"How To Disable ASP.NET MVC Url routing" which hasn't been answered (I don't think the responders understood why it was needed).
I have an existing application that uses AngularJS and MVC url routing to serve the templates. I want to remove the MVC url routing as it is redundant (see comment below. we are using webApi to return data via ajax so the views/controllers are not needed).
I have removed the call to RegisterRoutes in the Global.asax.cs. There doesn't seem to be anything in the Web.config apart from a reference to System.Web.Routing so I left it.
I am using IIS Express with Visual Studio 2012.
When the application runs I get a 403.14 Forbidden error. I have enabled directory browsing. I have set the start page in the project in Visual Studio but I get a 404 despite the file definitely being there.
I have tried creating a non-mvc website and copying the contents of the web.config to my application, but this didn't work.
if you mean by removing the .aspx on the end (www.something/home.aspx);
In C#, instead of using
response.redirect("~/home.aspx");
use
server.transfer("~/home.aspx");
AngularJs routing has nothing to do with ASP.Net MVC Routing.
Angular Routing:
Is used for deep-linking URLs to controllers and views (HTML
partials). It watches $location.url() and tries to map the path to an
existing route definition.
ASP.Net MVC Routing:
ASP.NET routing enables you to use URLs that do not have to map to
specific files in a Web site. Because the URL does not have to map to
a file, you can use URLs that are descriptive of the user's action and
therefore are more easily understood by users.
In essence, AngularJs routing deals with client-side routing (using the location Url), whilst ASP.Net MVC deals with mapping http Urls to the appropriate controller/action in the server-side.

Asp.net url routing in application having more than one page

I am using URL routing to make links to users profiles in asp.net, its work but the rest pages of the application not work , did i have to define a route for all pages or i miss something in somewhere.
I don't work with asp.net mvc but with asp.net web forms.
For profile page i want the routing but there is pages i just wont to use a asp x link to it
but all the pages now have the same URL defined in the routes in the global file.
I write this problem before two days always i have a problem.
You can debug your routes with ASP.NET MVC Routing Debugger Visualizer
or take a look at the blog of Phil Haack

Use System.Web.Mvc in non MVC ASP.NET Web Forms Application

We are developing an ASP.NET Web Forms application with REST modelled URL, for which we are using Route tables in global.asax. However, recently we came over a problem where the WebResource.axd and ScriptResource.axd files were getting routed as well. We wanted to use the RouteCollection.IgnoreRoute function. However, since it in System.Web.Mvc, it would mean that we would need to reference that dll in a non MVC Web Forms application.
Is it safe for us to continue with the approach. If anyone has a better way to ignore routes from within the Web Forms application please do share. Please also note that the application has been extensively developed in Web Forms and moving to MVC at the current stage is not feasible.
For web forms you need to use System.Web.Routing
Put this is Global.asax
void RegisterRoutes(System.Web.Routing.RouteCollection routes)
{
routes.Ignore("{resource}.axd/{*pathInfo}");
routes.MapPageRoute(
"Home", // Route name
"WWWWWW", // Route URL
"~/Default.aspx" // Web page to handle route
);
}
Did you know you could safely run an ASP.NET Web Forms and MVC application combined? Here are some links:
http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx
http://www.packtpub.com/article/mixing-aspnet-webforms-and-aspnet-mvc
Also, you can just use URL routing in ASP.NET 4 applications, as Registered User pointed out above. Read more about it here: http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx

Asp.net 4.0 Routing , accessing querystring in Web Forms

I have an existing Asp.net 4.0 web form application which has used Asp.net routing 4.0. Now, I have to add a route to my web form application. But i cant figure out how to access the querystring to my aspx page.
What i did is,
routes.MapPageRoute("Products","Products/","~/WebPages/Products.aspx?pid=4",false)
After adding that piece of code what i expected was that,
when i browse http:\localhost\mysite\Products i should be redirected to my Products.aspx page and there I should be able to access the Request.QueryString["pid"].
But I am not able to access the querystring.
I doubt whether this is allowed in Asp.net 4.0 Routing for Webforms. How can i fulfill my requirement?
Thanks,
M
Something like:
routes.MapPageRoute("ProductssRoute",
"Products/{*queryvalues}", "~/Products.aspx",
false,
new RouteValueDictionary
{ { "pid", #"\d{4}" }});
See http://msdn.microsoft.com/en-us/library/cc668177.aspx

Integration ASP.NET web forms blogging framework into ASP.NET MVC

Is there any way to use something like BlogEngine.NET (a blogging framework developed on the ASP.NET web forms model) in an ASP.NET MVC application? I want something where I can simply go to http://rooturl/blog and have it fire up the BlogEngine.NET site. I'm assuming that the ASP.NET MVC framework will intercept this call however and try to route it to the "BlogController"'s Index function though. Is there any way around this or is this a non-issue?
Scott Hanselman wrote on this a while back:
Plug-In Hybrids: ASP.NET WebForms and ASP.MVC and ASP.NET Dynamic Data Side By Side
But if I recall correctly, if you don't have a controller that matches /blog then the engine will default to sending the request to your /blog folder, and away you go, on top of that, as Scott notes:
Why doesn't ASP.NET MVC grab the request? Two reasons. First, there's an option on RouteCollection called RouteExistingFiles. It's set to false by default which causes ASP.NET MVC to automatically skip routing when a file exists on disk.
However, he goes on to note that you could just add the following at the top of your route definitions:
routes.IgnoreRoute("blog/{*pathInfo}");
Which would then ignore all requests to /blog/

Resources