We have MVC ASP.NET Web Applications written within the ASP.NET 4.* scope that we would like to phase across to ASP.NET 5. While we transition (as well as client-side JavaScript scripts/libraries, CSS, etc) we'd like the old app (which obviously contains Views, Controllers, Helpers, Utilities, Attributes, etc) to co-exist in an MVC/Web-Application ASP.NET 5 project, with the new (ASP.NET 5) codebase.
Firstly is this possible with minimal changes ? I have been doing some testing and a lot of reading - for the client-side libraries I should be able to handle the co-existence by copying the existing content into the wwwroot area via Gulp. My question is mostly around the server-side artifacts - for example I am using a framework (as specified in project.json) of "dnx46" (which seems to be the most appropriate for this purpose), but I am getting a number of conflicts (around missing assemblies) around simple things like Project references, ActionFilterAttribute & AuthorizeAttribute [eg. The type or namespace name 'AuthorizeAttribute' does not exist in the namespace 'System.Web.Mvc' (are you missing an assembly reference?)] (because they no longer exist in the System.Web.Mvc namespace), HttpContextBase, security (OWIN, etc) etc - note that I'm aware of including References which are reflected within the project.json file (and some that finish up inside the appropriate 'wrap' folder location)
If there is a preferred approach - some possibilities are
create a new WebApplication ASP.NET 5 project which among other things contains out of the box Bower, npm, Gulp, CodeFirst Migrations, Controller/Views, etc ready to go then copy your legacy project artefacts in
create a blank ASP.NET 5 project and start everything from the ground up (as per http://aspnetmvc.readthedocs.org/projects/mvc/en/latest/migration/migratingfrommvc5.html) then again copy your legacy project artefacts in
create a new WebApplication ASP.NET 5 project, then with a post-build event copy your new and legacy artifacts into a third vanilla project. In this way the old and new projects live in isolation and only get merged in at deployment time
separate concerns like Helpers, Utilities, Attributes, etc that are used within the UI project into a traditional Class Library project and only keep the bare minimum (Views, Controller, scripts, css, etc) within the UI (ASP.NET 5) project
Any ideas would be greatly appreciated.
I don't know that how your MVC 4 project is structured, I would prefer to create it from scratch using Blank ASP.NET 5 Template targeting dnx451. The thing I don't understand is previous .NET stuff like Authorize attribute are not found as they are available and I'm using it. Here are some stuff that might be help to you while migrating:-
Your EF Context and security classes should be considered as middlewares in ASP.NET 5 and should be configured in Startup.cs class which is not found in MVC 4.
Put all your CSS\JS files in wwwroot and make a reference _Layout.cshtml as root as normally (use gulp task runner for better performance.)
Must target dnx451, because dnx50 does not contain all of the libraries and it is about immensely in ASP.NET Core RC2 and RTM. (If you can't wait for RC 2).
If you're using Identity for Authorization, note that there is now a big change in Authorization Policy as can be found Here
It is a little bit difficult but it will optimize your team working and will make your project flow faster than before.
Related
The project that visual studio 2019 creates for an ASP.NET Web Application (.NET Framework) MVC5 comes with Bootstrap 3.x and many other outdated components. Not to mention unneeded things like modernizr.
If you update Bootstrap, you know need to modify the ScriptBundle in BundleConfig to get the application to start, and then modify the CSS to get the premade web pages to render properly.
Also, the folder structure is not the best.
Is there a project template out there that has all essential components updated, and a clean-up NuGet and folder structure?
I tried using Rider but they do not have a built-in template.
I went t the .Net Foundation GitHub and did not find any: https://github.com/dotnet?q=.NET+framework&type=&language=c%23&sort=
I also search GitHubub and did not see any: https://github.com/search?q=ASP.NET+Web+Application+%28.NET+Framework%29+project+template
I am looking for a project template that has the basic structure to create a Clean Architecture in .NET Framework and not .NET Core
I know it's legacy, but unfortunately, I need it for a university class (University courses take a while to get updated, and in this case, they claim that there are sufficient companies out there using ASP.NET MVC 5 to Merrit them teaching it) But yes, No one should be using this to start a new project they intend to put into a real-life production scenario.
Thank you
I'm currently trying to learn and understand all the new Identity bits and pieces with .Net Core 2.1/MVC. Previously, I have used MVC3 MVC Identity and it was straight forward - it automatically created the Model, View and Controllers and I could easily edit everything and anything.
With .Net Core, it seems to automatically inherit everything from the framework and I just don't easily understand how to override.
I've followed the guides located here, and have managed to scaffold all the pages (e.g. create user, reset password, login), however, this does not create any of the models or controllers.
Because of this, I now have a project with all the pages, but, it fails to build with all the models missing:
CS0246 The type or namespace name 'ChangePasswordModel' could not be found (are you missing a using directive or an assembly reference?
I feel like I am missing something obvious and I can't believe that I am struggling so much on something that ~10 years ago was simple.
How can I create/import the missing Controllers and models?
Identity comes with a default UI composed of Razor Pages and static files housed in a Razor Class Library. It's added by default when you either use AddDefaultIdentity to enable Identity in your project or explicitly call AddDefaultUI on any of the other Identity bootstrapping extensions methods (AddIdentity/AddIdentityCore).
Views and static files in Razor Class Libraries are embedded resources, and as such are treated as if they physically existed directly in the apps that reference them. However, anything that actually does physically exist in your app will be used before any embedded resources. As such, you can override anything coming from an RCL, simply by creating the same file in the same location as it exists in the RCL in your app. The Identity scaffold simply copies over the selected Razor Pages into your project such that they will override in this way.
Since Razor Pages are used for the default UI, there's no controllers or separate model classes. The models used for the views are established in the Razor Page codebehinds, so for each page you scaffold in, you should have both Page.cshtml and Page.cshtml.cs files added.
If your build is failing after doing the scaffold, the build is not seeing the *.cshtml.cs files (codebehinds). Verify that they do exist in your project's file structure. If they don't, there's some fundamental problem with the scaffold in your instance of Visual Studio, which will likely require reinstalling or at least repairing Visual Studio.
Assuming they are there, then there's something stuck in the build process. Occasionally files do get locked and Visual Studio will complain that it's missing references, when in fact it's simply missing the very assemblies those come from. In such cases, you can navigate into your project directly and remove the bin and obj directories completely. Then, come back into Visual Studio and do a rebuild. If you have more than one project, you should rebuild your entire solution, as it could be a project reference that's actually failing to build.
Does any one have any idea about multiproject area support in asp.net mvc 3? As it was degraded to future status in mvc 2. If it is still not included then should we look forward for ASP.Net MVC Portable Areas via MvcContrib. Can you share your expreriences?
What are the recommended way for managing a large application? I read about MEF. In what scenarios MEF is recommended?
I'm the development lead on ASP.NET MVC at Microsoft.
There are no plans to include multi-project areas in ASP.NET MVC 3. However, it's definitely an area that we plan to revisit in the future.
In the meantime MvcContrib's solutions are probably the best bet. The MVC Futures download still includes an old (and perhaps only semi-functional) version of the original multi-project areas feature. Because the full source code for it is also available, you might be able to construct a solution that is customized to your needs.
I need to have the same structure so I have figured out how to have areas as separate projects. There are no code changes needed, just a bit of configuration work you have to do.
I am going to create a blog entry on this but here are the basic steps.
Let's assume you have a single MVC application project and this will be your "shell" app.
right click on the shell project and "Add Area...". Type in the area name. This will create an Areas folder with your area in it. (This is not 100% needed but you do need the "Areas" folder and you can steal the XXXXAreaRegistration class for your application.)
Create a new MVC3 empty project in your solution to match your area. Move the XXXXAreaRegistration.cs file to the new project and adjust the namespace as applicable.
Delete the folder under the areas folder that the template wizard added.
Modify the web.config of the new project and take out the connection strings and the authentication, membership, profile, rolemanger sections. You don't really need the web.config but the razor intellisense doesn't work without it.
Create a virtual directory in the "Areas" folder of the shell project with the name of your area as the alias and point it to your "area" project. You will need to use IIS or IIS Express for this. I use IIS. In IIS express you have to modify the config file. I think ScottGu had a blog entry on how to do this.
Create a post-build event on your "area" project to copy the dll to the "shell" projects bin folder. My build event is: copy $(TargetDir)\$(TargetFileName) $(SolutionDir)\ShellProjectName\bin\$(TargetFileName)
In the shell web.config add the "area" project into the System.Web/Assemblies section.
Instead of 6/7 you can just reference the "area" project with the "shell" project and it works just as well. But, then you have to deploy all the "area" dlls every time. I am probably going to do some type of probing code to add the "area" assemblies to the app domain at app start up using reflection or MEF.
You might also want to edit your routing and add the namespace filter to it in both the shell app and the area app. This way you don't have to worry about duplicate controller names conflicting between the sell app and the area apps.
That's about it. Once I get a formal blog entry posted up I will try to remember to add a link to it here.
I blogged how I am doing this at http://bob.archer.net/content/aspnet-mvc3-areas-separate-projects if anyone is interested.
I'm developing MVC application where I currently have 3 projects in solution.
Core (it is supposed to be for Repositories, Business Classes, Models, HttpModules, HttpFilters, Settings, etc.)
Data access (Data provider, for instance SqlDataProvider for working with SQL Server datastore - implements Repository interfaces, XmlDataProvider - also implements Repository interfaces but for local XML files as datastore)
ASP.NET MVC project (all the typical stuff, UI, controllers, content, scripts, resources and helpers).
I have no Models in my ASP.NET MVC project. I've just run into a problem because of that coz I want to use the new DataAnnotation feature in MVC 2 on my Business class, which are, as said in Core, however I want to be able to localize the error messages. This where my problem starts. I cannot use my Resources from MVC project in Core. The MVC project references Core and it cannot be vice-versa.
My options as I see them are:
1) Move Resources out but this would require correcting a whole bunch of Views and Controllers where I reference them,
2) Make a complete restructure of my app
What are your thoughts on this? Also, Should I just move everything business related into Models folder in MVC project?? Does it even make any sense to have it structured like that, because we can just make subfolders for everything under MVC project? The whole Core library is not intended to ever be used for anything else, so there actually no point of compiling it to a separate DLL.
Suggestions appreciated.
Throw it all into one big .csproj boat and use folders to separate things. Its much easier to navigate folders than separate projects. You won't have to fight namespaces all the time and everything is right were you expect it. You completely eliminate any .sln kung fu when things aren't int he right location or assemblies need to be referenced and you can spend more time coding rather than moving .sln bits around.
Some people say it makes it harder to "swap out an implementation" which is baloney. Swapping the contents of a folder is just as easy as swapping the project.
The MVC source is what made me fond of this approach. They flatten everything out and its really easy to swim around their source code.
I would like to use a WebSite project instead of a Web Application project for an MVC project.
What is the best way to accomplish this and are there signifigant problems that I might run into?
(as a side note, my reasoning for wanting this is because I have graphic designers who put files into SVN but they don't get added to the "project" and don't show up on deployment or deployment testing. My thought was that switching to a Web Site project might prevent this)
You don't need to do anything special if you are not using CodeBehind files (if you're using them, it'll be more complex but anyway, it's an MVC app. If you're using them, don't!). Just take an MVC Web app project and put all source files (*.cs) under App_Code directory of the Web site. That said, I fail to see any advantage for it.
The application project allows you to use the Models folder to embed classes into. This would then be compiled for that web project. A web site does not provide for this directly. It would require that you use an assembly project to maintain all of your classes. Rather than converting from one project type to another (which I am not sure how you wold go about doing that) you can simply attach an assembly project to your web application and not store any classes in the model folder of your application.
Having said this, you should keep your web project as an application as there usually are view specific classes that are required such as a your view model classes that belong in the web project.