I know how to use areas in MVC3 - and I think it works very well, but I really want to make a higher level of seperation in my project.
I have multiple projects in an empty solution, a Domain project (containing my entities, persistence etc.) - a Framework project with tools, helpers etc.) and a UI project which right now contains the frontend and an area with the /admin for the solution.
Because a want to have a more clean solution for the UI and the Admin, I want to seperate these into two seperate projects.
How can I route the URL?
The url / is pointing at the frontend project.
The url /admin is pointing af the backend project.
Your /admin is nothing more than another virtual directory mapped to your admin app. It should work just fine like that, as it's how iis and asp.net works.
Related
I'm unable to get server side includes (*.html files) working in a .net core razor pages web application. I've made sure to have the appropriate handler in my applicationhost.config, but I'm thinking there's a different issue here. Any help is appreciated.
Why am I doing this? I have multiple web applications sharing the server side include files (for navigation bar, footer, head content, etc..). Each of these different applications may be of different Microsoft web architecture. Our goal is to move everything to .net core, but we have lingering web forms projects to deal with along the way.
I have performed a work around by taking the SSI file contents and using #Html.Raw to serve up the content. This is probably wrong also.
I went ahead and changed the file extension of the html files into cshtml which allowed me to treat these files as partial views. I'm using a prebuild event to copy these files from a shared solution folder into my project Pages/Shared/ssi folder. I also copy those partials into wwwroot/ssi for the other applications to use via SSI. Eventually all of the apps will use the partial views instead.
The problem with this solution is that it is not necessarily clear that all edits need to happen in the shared solution folder instead of directly in the project, but the documentation for the project will address this. I tried using linked files, but only one link to a specific file can be made in a project.
Not a perfect solution (to the problem), but this not a perfect website either.
I've been developing quite a complex web app for the company I am working for, and I have a problem with routing in asp.net mvc.
I know about the areas, but I don't want to use this approach.
Url structure I have now:
Default
Administration_Users/*
Administration_UserGroups/*
Configuration_Report/*
Configuration_Schematics/*
Dictionaries_DeviceCatalogue/*
Dictionaries_DeviceParameters/*
... and so on. (* means multiple methods inside, like Index, Edit, etc.)
Url structure I want:
Default
Administration/Users/*
Administration/UserGroups/*
Configuration/Report/*
Configuration/Schematics/*
Dictionaries/DeviceCatalogue/*
Dictionaries/DeviceParameters/*
I CAN use areas, but the problem is that these will later expand, as it is just one part of the web app. So, they will look like more this:
EquipmentManager/Configuration/Report/*
EquipmentManager/Configuration/Schematics/*
EquipmentManager/Dictionaries/DeviceCatalogue/*
EquipmentManager/Dictionaries/DeviceParameters/*
So, my question is: Is there a working namespace approach instead of area one?
Basically, I want InternalWebApp.Controllers.EquipmentManager.Configuration.Report controller that is located in corresponding folder map to views which are located in InternalWebApp/Views/EquipmentManager/Configuration/Report folder of my solution without having to map every controller manually in RouteConfig.cs.
I'm currently refactoring a huge ASP.NET MVC website. The main idea of what I'm trying to achieve is having a main (front) website and several separate websites in the same solution that can be deployed separately. The reason for that is that we have different teams working on a different project.
The current setup looks like this:
Main website ASP.NET MVC
Module 1 (Area)
Module 2 (Area)
other modules..
Common Business Layer
Common Data Layer
Common View Layer
When making changes to a module, you have to deploy the main website (so although Areas are acting as separate projects, they cannot be deployed separately). Areas are using RazorGenerator for the views. The Common View Layer generates Embedded Resources to be used in the main website/modules.
Any solution for that?
What I'm trying to accomplish right now is extracting the modules from Areas into full ASP.NET MVC websites and map them in IIS as subdomains to the main website. The problem here is that I have repeating views, styles, layouts in all projects and making a change to the main menu, style, etc. would mean going through all the projects and make that same change. Not a viable option.
Thanks for the ideas!
So the answer can depend also whether you want to have several solutions (*.sln) or it will be just one solution with several mvc projects.
Ad.1 Multiple sln / directories.
In that case probably interesting option is to configure virtual directory with some static content like styles, scripts etc. Such virtual directory can be quite easily configured on IIS: https://msdn.microsoft.com/en-us/library/bb763173.aspx
Ad.2 One solution, multiple MVC projects:
Then I'd suggest to add some solution folder like 'Common Presentation Layer Files' -> then I'd move all those files to be shared into that solution folder. Next in those MVC projects I would do following thing => right click => add existing item => as a link.
As the result you'll have a copies / shortcuts to the original files. You should do the updates only in that common folder and the changes will be visible in all other mvc projects. https://msdn.microsoft.com/pl-pl/library/9f4t9t92(v=vs.90).aspx Then you can publish your MVC projects separately and if properties of those static files are ok all the files will be copied during publish. So the structure would look like:
Solution:
MVC App 1 (proj)
MVC App 2 (proj)
'Common Presentation Layer Files' (solution folder)
other projects (projs)
I am starting to create a complete application in Visual Studio (.NET MVC). Does it makes sense if I put everything into a single solution and create three separate projects: Admin (used by staff to manage the app data), Web (public facing web pages), Shared (common data access and other code). This seems to make sense as later I might add a project for Mobile or an API or ...
If not, how do you structure your solutions/projects in Visual Studio?
If it were me, I'd have everything in one project and use areas to separate my views and models.
Example,
Project
Areas
Admin
Controllers
AdminController.cs
Models
Admin.cs
Main
Controllers
MainController.cs
Models
Main.cs
LoginLogout.cs
LoginForm.cs
Views
Admin
Shared
permissions.cshtml
admin.cshtml
Main
Shared
loginLogout.cshtml
loginForm.cshtml
master.cshtml
Index.cshtml
Walkthrough: Organizing an ASP.NET MVC Application using Areas
Areas provides a really nice way to section off pieces of your web application, and because it's all in the same project you can have all your sections use the same View Layout (Master Page) to make it all look the same from section to section.
Areas will map to urls like
http://somesite/main/index
http://somesite/admin/manage/index
In that example, you would not put your main section in an area, instead use normal model view controller patterns for the main part of the site, and only introduce an area for admin or other sections.
I have for some time created a few mvc websites. The other day my super suggested I put them all into one solution as they - more or less - is related to each other.
So I have come a long way with making the projects work more or less on their own.
Yesterday I hit a little bump where I am to put one project where you log in in order to register data. I have moved the login code to the first website (front?) and now that works. It was when I wanted to create the link (ActionLink) to link to the registration project, I started doing research on moving/transforming/changing a project into an area in mvc5.
So my question:
Has anyone moved/transformed/changed a mvc5 (or 4 or 3) project into a mvc5 area?
Is there something to worry about when doing this?
There are several things to consider when merging a project.
Routes and namespacing - If you controllers that have the same names in multiple areas, you will need to add a namespace entry to the route entries. Details here http://haacked.com/archive/2010/01/12/ambiguous-controller-names.aspx/
Make sure you have an area registration file that sets up each area. i usually add 1 area, then copy it's registration file and rename appropriately
Script and css dependencies - make sure that you get all those added to the root, seperate them in area folders if you like, then add them in at the correct area by using a section in your layout for dependencies
Adding a hyperlink between areas now needs to include the area name if you have conflicting controllers , you can check these answers How to specify an area name in an action link?
Think that about covers most things I have found when doing areas
Si