I have a custom .aspx web page that I use for browsing files on server.
Can I reuse that in MVC? Is there an easy way of doing this? ... or I have to rewrite everithing from scratch. I am prety new to mvc and the page use ajax for refreshing.
Thanks,
Radu
You have to rewrite existing pages from scratch. MVC uses completely different approach then WebForms. You can use both MVC and WebForms pages at one project, when upgrading, but can't use both approaches at one page.
Related
I use a new VS2013 project created with WebForms, MVC and Web-Api.
When using Aspx pages, they are displayed without .aspx extension.
Yes, I want to use MVC routing sometimes, and also aspx pages without any routing, but I would like to see .aspx extension.
Can I do that ? Thanks.
(In an old WebForms project I manually Added MVC fonctionnalities both webforms and mcv worked fine, so I think it's possible...)
I have an existing ASP.NET web site running on .NET 4.5. I need to integrate an ASP MVC 4 project (which is its own fully-functional web application) into it so that when the user navigates to a certain page, the ASP MVC application is launched within the page - almost as if it were in an iframe.
In the main solution I can set both as startup projects, but this is obviously not what I am looking for. Can someone point me in the direction of how to do this? I have never used WCF before, but is this something that it could be used for? Thanks for anything!
You can create a hybrid webforms - MVC application.
To do this you need to:
copy the MVC configuration from the web.config of a new MVC project to your WebForms application web.config
create the standard MVC 4 folders (at least Views, Controllers)
reference the required assemblies
copy the web.config inside Views from the MVC project to the WebForms project Views folder
change the routing configuration to ignore routes including .aspx/.ascx, so that they are handled by web forms, and not MVC (do this also for .ashx, .asmx, or whatever other web forms based artifacts)
This way you have a single ASP.NET application which supports MVC and WebForms, and use the same authentication, session, and so on.
Then you can make this kind of integrations:
- make pages that are fully MVC or fully webforms. If you're using master pages, you need to create a master page for web forms, and a layout for MVC (this can be very hard or quite easy, depending on its content and design)
- make a webforms page and integrate the MVC pages using AJAX and MVC partial views
Aprt frommy comments, this blog entry will help you a lot: Integrating ASP.NET MVC 3 into existing upgraded ASP.NET 4 Web Forms applications
By the way, this is not theoretical... I have a web application with lots of pages, areas, and views, which uses this technique, and it works flawlessly. I had to redo the design of the master page (layout and CSS) so that both kind of pages look alike. I was lucky enough to have a menu rendered in a webforms placeholder using a SQL XML query and an XSLT, so re-using it in the MVC layout was absolutely easy. You can do something similar to this in your master page and MVC layout (I mean rendering the HTML manually, and using it in both pages, so that it's done only once)
You can take some time to get it to work, but it's worth the effort.
I noticed a lot of ASP .Net sites does not have the URL ending with ".aspx".
An example would be:
- https://stackoverflow.com/questions
Did they create a Questions folder and put a Default.aspx inside?
In that case, wouldn't there be A LOT of default.aspx in many folders which is hard to maintain (even though it is user-friendly)?
Thanks y'all.
StackOverflow is written using ASP.NET MVC. The MVC framework does not use .aspx files.
The way it works internally is by using routing tables - see an overview here.
You can also do this with ASP.NET and .aspx files or you can use URL rewriting. You can read about the differences here.
You can refer to any URL rewriter or a routing technique for that. If you look at the new AS{.NET MVC, it works on that model only.
You can use Url Rewriter to remove extensions from the urls of your website.
ASP.net has a routing framework you can use even if you are not using ASP.net MVC
Official documentation: http://msdn.microsoft.com/en-us/library/cc668201.aspx
Also as previously stated ASP.net MVC works like this out of the box and you can also use URL Rewriting
With ASP.NET 4.0, you get the benefits of URL routing (nice, clean URLs) with ASP.NET webforms, too — see:
Routing for Web Forms in ASP.NET 4.0
URL Routing with ASP.NET 4 Web Forms (VS 2010 and .NET 4.0 Series)
Basically, what you do is define a route like
/question/{id} or /question/{title}
and you then define what ASPX page this is being routed to. Quite nifty!
i have a classic web project and i want to use asp.net mvc url routing just for rewrite url. is it possible without make much changes to my web project?
Routing is not part of ASP.NET MVC - it's just part of ASP.NET itself. The good news is that it works with both MVC and WebForms (ASPX files). Check out Phil Haack's blog post on how to get this to work.
The only changes you need to make to your application are to add some configuration items to web.config and then register your routes in global.asax.cs (or global.asax.vb if you're using VB).
System.Web.Routing, while shipped with ASP.NET MVC, is not technically part of the MVC framework. You can in fact use it as part of a regular ASP.NET webforms project.
Definitly possible for .net 4.0, so like in 2 months.
Also, google shows alot of content on how to do it today.
As others have said routing is now built into .net 4 and can be used for both mvc and web forms. ScottGu has a post about how to use routing in webforms and can be found here.
Hope it helps.
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/