In my first attempt at an MVC web application I have a fundamental question:
Suppose I have a webshop that has "articles". The administrator of the site will have to view, add, edit and possibly delete these articles, so I guess I could create routings/URLs like this:
/articles/view/
/articles/add
/articles/edit/3
But viewing articles is not just for the administrator of the site, but also for the visitors. The most obvious URL wouls also be /articles/view/. So what is the best practice way of differentiating between URLs for the administrator and for the visitors? (and IS there a best practice way?) Should I do this:
/maintenance/articles/view - for the administrator
/articles/view - for the visitors
Or is it better to serve them the same URL and give them a different view, based on whether or not they are logged in or not?? Are there any specific advantages to using one over the other,or is it just convention?
Thanks,
Erik
It kinda depends on how your site is structured.
If you have a strict distinction between CMS (for site maintenance ) and public page, then your routes, most likely, will have completely different routing schemes for each part. They might even be mapping two separate applications.
On the other hand. If you want to create administration interface, which is integrated into the public site ( something along the lines of Inplace Editors ) then you will be using exactly the same routing scheme as public page, and your authorization level ( are you a visitor or admin ) will be determined on serverside.
Related
I would like your guidance on this.
I'm trying to build a website that has two "players" (which, I assume can be translated to "roles"?). One player is "consumer" and the second player is "supplier".
Both are interacting through mutual (sql server) database.
Now I would like to have totally separate systems each player, with totally different authentication mechanisms.
However, I would like to have the consumers system as sub-domain of the main domain, i.e., I would like to have the consumer system under 'mydomain.com', and the suppliers system under 'supplier.mydomain.com'.
However, I can't figure out how to technically do this? Can I create another web project in my solution, call it 'suppliers' and let it include all the features of the suppliers system?
Or should I create separate controllers for the suppliers features inside the main project?
The first option sounds most "clean" to me, however, how can I route the user from the main (the consumers) website to the suppliers website based on the subdomain?
If I choose the second option, how can I make sure that user which authenticated as customer will not be able to perform as supplier?
This is probably very common task to do, any good tutorial or example for this?
You will create two separate IIS applications - one for your consumers and another for your suppliers.
You will then set the host headers on each to your required domain and subdomain. IIS will then take care of routing URLs to your separate applications. Instructions for setting IIS host headers here https://technet.microsoft.com/en-us/library/cc753195.aspx
As for managing application code, given you want complete separation I would suggest creating three Visual Studio projects:
Web application for consumers
Web application for suppliers
Class library of shared code - database logic etc
You are then able to develop and deploy each web application independently.
In terms of tutorials, there is quite a lot available, here are a few which will help you:
https://web.archive.org/web/20211020150710/https://www.4guysfromrolla.com/articles/122403-1.aspx
https://www.simple-talk.com/dotnet/.net-framework/partitioning-your-code-base-through-.net-assemblies-and-visual-studio-projects/
https://softwareengineering.stackexchange.com/questions/207101/managing-multiple-projects-that-share-code-customization
for this problem, so use "Area" =
https://msdn.microsoft.com/pt-br/library/ee671793(v=vs.100).aspx
I've created three related ASP.NET MVC web-applications that sit in IIS like so:
root
|-Emailing
|-InternalManagement
Where the root site is customer facing.
The three sites have different security requirements and I wanted to be able to modify one application with less worry about breaking the other two.
However both the root and the internal management site need to have links to the emailing site.
I'm using T4MVC.
Now I've separated the T4MVC helpers for each project by modifying the HelpersPrefix, and root and InternalManagement reference emailing so for example I can do something like:
Url.Action(MVCEmailing.CustomerDocuments.Index())
Which almost works - except the actual URL produced will be:
For the root application:
http://mydomain.com/CustomerDocuments/Index
for the internal management application:
http://mydomain.com/internalManagement/CustomerDocuments/Index
What I need in both cases is for the URL produced to look like so:
http://mydomain.com/emailing/CustomerDocuments/Index
What's the best way to go about doing this?
Copying from the T4MVC doc:
One key concept to understand about T4MVC is that it is just a thin
layer over MVC. e.g. while it provides strong typing, in the end it's
just putting values in a dictionary, and using standard MVC to
generate the routes.
One thing I often suggest when people have questions is to first
figure out how they would do things without T4MVC. If you have no idea
how it would work, or think it may not be possible at all, then you
are probably expecting too much of T4MVC! Generally, it will not do
anything that MVC does not support.
In your case here, I'm not convinced that you could do this with plain MVC, because each of the application does not have knowledge of the other applications' routes. And generally, I don't think that MVC routing can ever general links that go outside of the current app.
I would like to know if the following is possible. I have a website called www.myweb.com. This website could be a directory of say football teams. The list of teams could be found here
www.myweb.com/home/teamlist
On selecting a team one would be take to
www.myweb.com/teams/teama or
www.myweb.com/teams/teamb etc
the content under the teams area would be related to them e.g.
www.myweb.com/teams/teama/fixtures
www.myweb.com/teams/teama/news
i have the above working but would like to know if it is even remotely possible to have a separate website for each team which still uses the current models, views and controllers e.g.
www.teama.com
would go to display the data from
www.myweb.com/teams/teama
where 'teams' is the controller and 'teama' is a parameter for a 'details' action. Also doing
www.teama.com/fixtures
www.teama.com/news
would display the same stuff as
www.myweb.com/teams/teama/fixtures
www.myweb.com/teams/teama/news
many thanks and hope i have worded it ok.
Rudy
I would consider using IIS URL Rewriting in that case.
Have a look at MVC Domain Routing, I'm still researching it myself as I have a similar required as yourself but I think that should do what you need.
The following links might be handy:
ASP.Net MVC Domain Routing
Bolt on multi-tenancy in ASP.Net MVC Part I (link to Part II is on the page)
I'm pretty new to ASP.NET MVC and I just want ask of this scenario is possible and, if so, could anybody provide any resource links on how to implement it.
Say I have a site that can be accessed from www.mysite.com, can I also have the same site load up through www.mysite2com, www.mysite3.com and so on? effectively providing the ability to run multiple sites from a single code base?
The idea is to have the site content and style sheet change depending on site visited but keep the structure the same.
thank you very much for any help you can provide :)
Kris
Yes, this is possible
http://web.archive.org/web/20100119084358/http://just3ws.wordpress.com/2010/01/03/skinning-your-asp-net-mvc-application-based-on-your-sub-domain
This example uses subdomains of the same domain but nothing stops you from using the same logic and have different images/CSS/paths etc generated based on full HOST/domain name
This is a ASP.NET MVC beginner question (I'm in phase of developing NerdDinner)... I have assignment to create ASP.NET MVC cms (with its own design) and portal (also with its own design) that will display data that's being handled by CMS. I was wondering if I will have to make two individual projects in Visual Studio or I will have to use one project and place portal section in specific folder.
I know that my question is a bit premature (according to fact that I still haven't finished tutorial) but I'm bit impatient :)
On server (commercial hosting) I would use only one hosting account... this thing with URL routing is a bit confusing to me, CMS is practically also optimized for SEO.
I would like to the structure of URL to be:
---- PORTAL ----
www.domain.com
www.domain.com/Menu1/Submenu1
www.domain.com/Menu2/Submenu1/SubSubmenu1...
etc.
---- CMS ----
www.domain.com/CMS
www.domain.com/CMS/Whatever
Thanks,
Ile
It all depends on the functionality of the portal and the MVC cms.
For starters I would have a separate solution for the Model/Data Access that way you can have as many MVC projects without duplicating your data access.
From your desired url structure I would probably have the CMS as a separate controller and sub folder. Alternatively if your using MVC 2 you could look at the areas support which will probably give you a little more flexibility.
If you want the solution to be a bit more complex/flexible you have a number of options:
If both the portal and MVC cms are going to have he same functionality and page layout you have two master pages and determine which mater page to show when returning the view. You would specify this in the routing so multiple routes would point to different controllers.
If the layout/functionality differs slightly but one controller can still manage both you could have a separate controller project and two mvc projects which only contains the views, javascript and images so both mvc solutions look at your controller solution. With this option you would probable end up setting up two websites on your domain one under the root and the other under the CMS folder (in your MVC app you will prob need to block routes to /CMS so it will be processed by your CMS app).
Finally if both differ hugely have two separate projects but keep your common data access project, as above you may need to set up two sites on your hosting package.