I'd rather be doing MVC as the regular WebForms development eats my soul.
However, I've been given a fairly sizable WebForms project to add a bunch of features to.
Is there anyway for WebForms and ASP.NET MVC to coexist in single project or even jointly handle the website? I know I am asking for a hack.
Here goes...
Make sure your project is targeting .NET 3.5
Add references (and make sure they copy to local) the big 3 assemblies for MVC (System.Web.Mvc, .Abstractions, .Routing)
Add a Global.asax if you don't already have one in your project.
Go to Global.asax code behind and add the necessary code to make it look just like an MVC Global.asax (I'm not going to type it out, just create a new MVC project and look at the Global.asax and add the things your current Global.asax code behind is lacking)
Create the top level folders for "Controllers" & "Views"
Create sub-folders of "Views" for your corresponding controllers (ex. Views -> Home)
When you add .aspx files to you view folders be sure to change the base class from System.Web.UI to System.Web.ViewPage and remove the tags
Start a new blank MVC project and do a find for "UrlRoutingModule" in the web.config and add those refrences to your WebForms web.config in the same places
Check the system.web -> pages -> namespaces node of the new MVC project and add the MVC specific ones to your WebForms web.config
This is a very rough explanation but you asked for the cliff notes. Moral of the story is to follow along with a new/blank mvc project and add the necessary entries in web.config, reference the necessary assemblies, and create the correct file structure for the mvc pattern.
I haven't done it - but it appears to be possible according to this Chad Myer's blog post. It's a bit old.
http://www.chadmyers.com/Blog/archive/2007/11/30/asp.net-webforms-and-mvc-in-the-same-project.aspx
This is what I did to add MVC5 to an existing Web Forms project
Create a new ASP.NET MVC project. You can use it to copy info to your existing project.
In your existing project, use nuget to add the references. This will also update your Web.config and add the jQuery files. Copy this in your Package Manager Console
Install-Package -Id "Microsoft.AspNet.Mvc" -Version 5.2.2" -ProjectName ExistingWebApp
Install-Package -Id "jQuery" -Version "1.10.2" -ProjectName ExistingWebApp
Install-Package -Id "jQuery.Validation" -Version "1.11.1" -ProjectName ExistingWebApp
Install-Package -Id "Microsoft.AspNet.Web.Optimization" -Version "1.1.3" -ProjectName ExistingWebApp
Install-Package -Id "Microsoft.jQuery.Unobtrusive.Validation" -Version "3.2.2" -ProjectName ExistingWebApp
Install-Package -Id "Modernizr" -Version "2.6.2" -ProjectName ExistingWebApp
Copy BundleConfig, Routeconfig, FilterConfig and any others you need to App_Start
Add the register lines from Application_Start to Global.asax. You can get them from your new project.
Add these keys to the <appsettings> of your Web.config
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
Add a reference to the Microsoft.CSharp assembly
Add the Views and Controllers folder
Now you can start adding views and controllers as you would do in any Mvc project
If you have room for another book I highly recommend Steve Sanderson's book http://bit.ly/1W03Tv (I'm not a mole...it's just helped me a ton). He has a chapter in there about "Combining MVC and WebForms".
I thought about summarizing the process out here but it's a bit lengthy. Give it a look if you get a chance.
Now in 2011 we have .NET 4.0 and is fairly easy to combine them. Just start a new MVC3 project, add a HomeController and a view (i.e. Home/Index.cshtml), then add a new folder, let's say /Admin, then add a web form inside it like /Admin/Default.aspx... that's it, run it, the home page will use MVC, the admin section will use web forms.
Also - in order to add the context menus, add the "MVC" project type ({E53F8FEA-EAE0-44A6-8774-FFD645390401}) to the project file as such
<ProjectTypeGuids>{E53F8FEA-EAE0-44A6-8774-FFD645390401};{...};{...}</ProjectTypeGuids>
Related
I worked on exists umbraco project, and in this project there is a model builder button that generate model and I can copy them to my visual studio and use them as model.
Now I started a new project, but In the new App I don't have the generate model button
This is my Previous Project
And this is my current project (without the generate model button)
How can I add models builder to my project, And How can I know which model builder uses on my previous project.
You have PureLive models configuration set up, which means exactly that your models are autogenerated and you don't need to fire it up via button. It may be helpful but also dangerous :)
The configuration is in you web.config file and you can change the mode of storing models there.
<add key="Umbraco.ModelsBuilder.Enable" value="true" />
<add key="Umbraco.ModelsBuilder.ModelsMode" value="Dll" />
Check more info at Stephan's Wiki: https://github.com/zpqrtbnk/Zbu.ModelsBuilder/wiki/UsingTheModelsBuilder and choose the best way to handle models inside your instance of Umbraco.
I've created Internet MVC Application with Individual User Accounts Authentication, but now this project should be intranet with windows authentication... How to switch authentication, when project is almost done? I'm not guru in MVC and this is new technology for me, so any help please and if possible with all steps in description=)
In the Web.config of you project. The first step would be change:
<authentication mode="Forms">
</authentication>
to
<authentication mode="Windows">
</authentication>
Selecting your project and hitting F4 for the properties window allows you to change the authentication method.
However instead of me putting step by step in here just use this very easy to follow tutorial:
Enabling Windows Authentication
Since I found this question through google attempting the same thing, and Firearm's link doesn't quite do the process justice, I'll attempt to list the steps I went through here. Obviously, if I tell you to remove something, that only means if you aren't using it otherwise. I don't think you have to do these steps in any particular order.
Also, I'm using Entity Framework, so you'll have to look elsewhere to remove it.
in the solution explorer, highlight your project and press f4. This will bring up the properties window for that project. Disable anonymous authentication. Enable windows authentication.
Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution... uninstall anything with "owin" in the name, Microsoft.AspNet.Identity.EntityFramework, and Microsoft.AspNet.Identity.Core.
Open your Web.config. Under runtime, under assemblyBinding, remove all the dependentAssembly's for Owin stuff that got left behind. Under system.web, replace <authentication mode="None" /> with <authentication mode="Windows" />
<authorization>
<deny users="?" />
</authorization>. Under system.webServer, remove handlers. under modules, remove <remove name="FormsAuthentication" />.
Remove the Account and Manage controllers and views. Remove the ManageViewModels from your models.
Under App_Start, get rid of IdentityConfig and Startup.Auth.
At the top level, right next to your web config, is Startup.cs. Get rid of it.
Make a new ApplicationDbContext. It should derive from DbContext. Get rid of throwIfV1Schema: false in your constructors. Then you can get rid of IdentityModels from your Models folder. Add a new migration and update your database.
Obviously you'll have to clean out any references you've made yourself to Identity.
Possible additional step:
* remove _LoginPartial view. The _Layout view will then be updated to replace partial display of that view with this line:
<p class="nav navbar-text navbar-right">Hello, #User.Identity.Name!</p>
Searching the exact same problem led me to this article, however the answers are a bit old, so with ASP.NET using MVC 5 this should be detailed documentation from Microsoft:
To detect Windows Authentication in an MVC project, the wizard looks for the authentication element from your web.config file.
<configuration>
<system.web>
<authentication mode="Windows" />
</system.web>
</configuration>
To detect Windows Authentication in a Web API project, the wizard looks for the IISExpressWindowsAuthentication element from your project's .csproj file:
<Project>
<PropertyGroup>
<IISExpressWindowsAuthentication>enabled
</IISExpressWindowsAuthentication>
</PropertyGroup>
</Project>
Found at Diagnosing errors with the Azure Active Directory Connection Wizard
For my specific problem it was switching to Azure AD rather than Windows Authentication (which was preset), there are more steps found at the developer network website.
I'm afraid I'm a bit late with my answer to you're question on how to implement the SwitchUser functionality, but for those of you who are still struggling with this (even Microsoft SharePoint still can't get it to work...), here's how it's done: (I just finished writing the article)
Switch User Functionality using MVC4 and Windows Authentication
If you need more information on how to get Windows Authentication workong for an Intranet Website using AD and Windows Server 2012 (or Higher), then take a look at my following article:
Windows Authentication on Intranet Website using AD and Windows Server 2012 (or Higher)
Happy coding!
In Asp.net MVC Razor we can use the _ViewStart.cshtml file to define the default layout for our views. That is fine, but why did we loose the web.config setting that was available with web forms engine in system.web > pages.masterPageFile setting?
Why is that important? Because web.config allow automatic environment transformations.
Manual solution
Of course we can put the default layout name in either appSettings and refer to that in the _ViewStart.cshtml or if we have application specific configuration section add additional property which makes things a bit more clear and polished...
But is there any other way that doesn't include code?
Asp.net MVC team should add the layoutFile configuration setting to system.web.webPages.razor > pages element, shouldn't they?
The main question is
Am I missing something that is built-in and I don't know about? Something that requires no code at all similar to WebForms engine?
Asp.net MVC team should add the layoutFile configuration setting to
system.web.webPages.razor > pages element, shouldn't they?
Feel free to open a ticket on the MS Connect site.
But while waiting for your ticket to be analyzed by the development teams and probably added in a future version of the ASP.NET MVC framework and the WebPages you could always do the following in your _ViewStart.cshtml:
#{
Layout = ConfigurationManager.AppSettings["Layout"];
}
and then define the layout in your web.config file:
<appSettings>
<add key="Layout" value="~/Views/Shared/_Layout.cshtml" />
...
</appSettings>
Another possibility is to write a custom razor view engine in which you set the layout dynamically.
I have downloaded the source code of the MVC 3 to learn How it runs .
Many people said that the MVC interceptes Http’s requests by the UrlRouting Moudle Class.
I know when you custom a HttpModule ,you need to register it like that:
<system.webServer>
<modules>
<add name="test" type="WebApplication2.MyModule1,WebApplication2"/>
</modules>
</system.webServer>
So Asp.net mvc application Web.config file Should be have the configuration section:
<add name="UrlRoutingModule"
type="System.Web.Routing.UrlRoutingModule,..." />
But I can't find it int the web.config file,when I create a new Asp.net MVC application .
Someone said the IIS 7 would automatically added it .
When to IIS7 add the configuration section?
How the IIS7 Difference it is a MVC application or WebForm?
you have a few questions in there. The web.config is located in the root of your start up project when you open it in Visual Studio, else if you 'explore' the application within IIS, this should take you to it also.
Not all modules are included in the web.config, some are also in the machine.config. This is usually in C:\WINDOWS\Microsoft.NET\Framework\<version>\CONFIG
Hope that helps.
Hi I am installing Umbraco to the root directory of my website. And also I want to install my wordpress blog to a subfolder in the root directory.
However any request to the subfolder is being intercepted by Umbraco and it is showing that document URL cannot be found. Is there a way to make Umbraco ignore certain subdomains?
You can tell Umbraco to ignore certain paths or folders in the web.config.
You need to update the following entry in the appSetting section of the web.config:
umbracoReservedPaths
Add the subfolder you wish Umbraco to ignore in there.
i.e.
<add key="umbracoReservedPaths" value="/umbraco,/install/,/wordpress/" />
There are more details on the Umbraco web.config settings in on our.umbraco.org
it's useful for binding too:
<add key="umbracoReservedPaths" value="~/umbraco,~/install/,~/http-bind/" />
~/http-bind/
Thanks Tim Saunders
You can also use umbracoReservedUrls to tell umbraco to ignore specific pages:
<add key="umbracoReservedUrls" value="/mypages/regular-page.aspx" />
This can be set up with in IIS by setting up the blog as a separate application with in the umbraco site.
However if you are trying to make a sub-domain there is no reason why this should be in the same site, I would say it is best to create a separate site with in IIS or purchase another hosting account to host the blog separately