I have a website developed in ASP.NET Web Forms with .NET FrameWork 4.5.1
We have a requirement to build a replica of the site for mobile devices (responsive doesn't work for us in this case) so I ended up thinking of doind this part of the site with ASP.NET MVC.
Note before you continue: I know there are a few questions answered about this topic and in the web there are some articles on how to mix them. But none of them works for me because I'm trying to use the One ASP.NET Framework to avoid going through a lot of manual work.
So, what I did was:
The project structure looks like this:
And here comes my problem: If I run any of the ASPX pages, they run ok. When I go to the /Mobile/Home/Index it says the resource is not found. I suspect this is because the App_Start folder doesn't exists in my project and Starup.cs isn't there either so the website doesn't know anything about MVC routing.
Question
How can I add the App_Start folder and the Starup.cs with defaults values without suffering the process (avoiding copy/paste or manual processes)?
How can I make this both (web type projects) live together as they say it can be done with the One ASP.NET Framework?.
Thanks!
To do this, right click you project and click Add> New Scaffolded Item… This will bring a dialog to choose the Controller class like below. Click “MVC 5 Controller – Empty”. Visual Studio will download and configure all the items for you to start working on MVC.
Luckily, the answer is yes. Combining ASP.NET Webforms and ASP.NET MVC in one application is possible—in fact, it is quite easy. The reason for this is that the ASP.NET MVC framework has been built on top of ASP.NET.
You can create an area by right-clicking on the project in the solution explorer -> Add -> Area.. , as shown below. Enter the name of an area in the Add Area dialogue box and click on the Add button. This will add an admin folder under the Area folder, as shown below.
Create the Model and ControllerIn Solution Explorer, right-click the project. Select Add New Item. Under Installed Templates, expand Visual C# and select Web. Then, from the list of templates, select Web API Controller Class.
You'll need to register the areas in your Global.asax (add it through the Add Item menu option if it does not exist):
public class Global : HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
AreaRegistration.RegisterAllAreas();
}
}
This will enable the link to your Mobile @ localhost/{ProjectName}/Mobile/Home
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With