Front end page urls - umbraco

I have an umbraco installation.
I published a content named "Account" and umbraco gave it this url /account.
Fair.
Then I published a content named "Register" under content Account (I allowed Account Doc Type to have Register Doc Type as child).
I would expect the url of the new content to be /account/register, but umbrace gave it /register.
Why is this happening? What's the point of allowing child content types, and building a content tree, if the urls are all from root? As a newbie to umbraco, I consider it a logic flaw. For a CMS that claims to be friendly, that's not friendly at all. I'm a developer but I can't waste half of my day looking for umbraco answers and tutorials online. A friendly CMS should be self explicatory while being used, and should take care of all common assumptions a newbie may have.
How can I make the Account->Register content node to appear in /account/register url?

I think what you're seeing is a side-effect of a feature in Umbraco that is supposed to support the pattern most develops use when creating an Umbraco website.
The best practice when building Umbraco websites is to create a "Website/Root/Site" document type and place this in the root of your hierarchical content structure. Beneath this document type you place each of your pages as direct children. This allows you to set hostnames and culture on your site as well as it allows you to keep your entire site in one "bundle", and it also allows you to do multiple subsites within the same Umbraco website. It is pretty common practice to structure your website this way.
However - as you expect - this would give your URLs such as domain.com/website/account/register due to Website now being an actual content node in Umbraco. As this is really not something anyone would want - Umbraco has a built-in feature allowing the top level node to be hidden from the URL path. This results in your URLs being domain.com/account/register in this case.
If you however consider your site - this feature results in your register page getting the URL: /register since the /account part is a top level node that will be ignored when generating URLs.
This behavior is triggered by the setting umbracoHideTopLevelNodeFromPath which can be found in web.config of your site (true by default).
I would however recommend that you do not change this setting and instead add in the root node for your site as it will make things easier for you to manage in the future - it is also the best practice way to structure a site.
This should result in URLs being generated the way you are expecting them to be. Child nodes will have URLs that reflect their name and location in the content tree.

Related

How to add an mvc page to umbraco

I have Umbraco 7.5 and I need to know how to create normal MVC pages for adding new data to my site.
Lets say I have a Doctype "Node" in back-office. I want to let some people be able to add/edit some nodes without going through back-office. How can I do it?
I've tried to create add my view and controller (the MVC way), but apparently Umbraco hijacks all routing and my controller won't hit at all.
I've googled the matter (which is hard since I am not looking for Umbraco forms :| )and I've found this. But I prefer not to add my form as a part of other page. I mean, does it make sense to create a page in back office from type "something" and then on its template I do my add/edit form of another type? Seems strange, right?
I appreciate any ideas/ solution to this matter
You have a couple of options here. You can create a physical page for the editor to sit on, and add the editor as a SurfaceController action (basically an MVC Partial with Postback, that is still part of the Umbraco pipeline). Your form can then use the Content Service API to update the details. The advantage of this method is your code will have access to all of the Umbraco methods and templating out of the box. You could also use WebAPI controllers for the form if you want to do it all client side with JS requests.
You could also use route hijacking: https://our.umbraco.org/documentation/reference/routing/custom-controllers this allows you to have your own custom controllers for Umbraco routes, rather than using the default Umbraco ones. This is a bit more work to set up.
Finally, you can also tell Umbraco to ignore certain paths entirely, and you could run your controllers on those paths. The disadvantage here is that as the routes are being ignored by Umbraco, you don't automatically have access to all the useful Umbraco templating etc.
I've used the first method recently, and it works fine. The only caveat is that allowing users to edit nodes will fill up the version table quite quickly if a lot of users are editing a lot of nodes (every time a node is saved, a version is created). If you're going down this route, you may want to investigate something like Unversion: https://our.umbraco.org/projects/website-utilities/unversion/ which helps to keep old versions more manageable in situations like this.

Access static content from area w/o "Areas" in url

I am currently working on a web app with a small web page on the root level and several (more complex) web pages in areas.
All area-based web pages have static content that is independant of each other, so each of them has it's own content folder.
Unfortunately the resulting url's for the static content contains the string "Areas", for example
http://myappurl/Areas/MyArea1/Images/myFile.png
Since Areas are a technical implementation detail and nothing that the user should know (or care about), they do not belong in the url.
How can I fix that?
I don't want to create another root-level directory for each area (would be confusing and error-prone), but I don't really understand how I could modify routing to allow this otherwise.
Help would be appreciated :)
By default, ASP.NET does not handle requests to .png files.
Scott Hanselman has an article that explains how to change this functionality. Link: Back to Basics: Dynamic Image Generation, ASP.NET Controllers, Routing, IHttpHandlers, and runAllManagedModulesForAllRequests.
If you follow the instructions there, then you will be able to gain control of how requests to all png files are routed. So, you get to define routes the same way for the file nested within the area as you do for any other View/JSON/XML. The trick is then to set the appropriate content type and render the image as a filestream.

microsite in umbraco

I am relatively new to umbraco and have just got the site build but the clients request for a microsite with a completely new look and feel.
So how do I set up a new microsite in umbraco.
Please Help.
Thanks a ton
To give pages within Umbraco a completely different look and feel from the others, there's a few different ways you can go. Obviously there's more than one way to solve a problem, but I'll just mention a few that I can think of and explain how they'd work.
Create a new master page template that has your new design, then create child templates for each document type, to include a home page, a standard text page and anything else you may need. Assign these templates to the document types that will use them.
Pros: Easiest approach. Allows most flexibility in design.
Cons: The user can choose the wrong template or forget to set the right template.
Create separate templates as in option 1, but also create separate document types. Assign the templates only to the new document types. Each document type can extend your existing ones to inherit the same properties or you can create entirely new ones.
Pros: Ensures that the uses uses the correct template all the time. Allows most flexibility in design. Allows site specific customization - can add or remove properties.
Cons: The number of document types doubles and therefore the amount that appears for the user to select. Of course the number that they see can be limited by what templates they are allowed to create.
Use existing templates, but include a check that determines which site is being visited, depending on the path or subdomain, etc., then dynamically load different style sheets.
Pros: You do not need to create separate templates or document types for the microsite.
Cons: Your master template's markup will have to be generic enough to compensate for both designs, therefore it isn't as flexible.
Once you choose an option for how you will structure and style the pages of the microsite (and remember that my list is not conclusive), you will need to determine where to setup the node structure. The best option here, if the microsite will be subdomain or if it has its own domain, would be to add it as a separate home node first and then add all of its own pages below it. Then you can actually setup a different host reference for the site within Umbraco. There have been a few answers on SO that mention how to do that:
Assigning hostnames in umbraco
Publishing multiple sites on a single instance of umbraco
Here are some basic steps to allow Umbraco to use other domain names:
Setup your web server to accept host headers for the specific domain/subdomain. In IIS 7.5, this can be done by adding bindings for the domain/subdomain.
The new node needs to be a direct child of the Content node.
Right-click the node and choose "Manage hostnames". Then add the domain/subdomain URL.
Hope that helps! Feel free to ask more questions.

ASP.NET MVC Theming Best Practice?

It has now become a requirement that my existing project requires a different 'theme' for different clients. I have never had to do this on an ASP.NET MVC project and it doesn't seem like ASP.NET Theming and MVC go together very well.
I would say that 75% of the CSS will remain the same with the rest being changeable. It wouldn't have to be able to switch on-the-fly as they will be deployed as separate web sites (probably on different servers).
Just wondering if there was a preferred method for doing this sort of thing? I was thinking of just having a base CSS with separate 'client-specific' ones with overriding rules. The client css name could then be be set in the web.config and brought through to the master page for declaration.
Am I on the right track there?
We do this, with a similar approach as the one you described. Base CSS is always loaded, and CSS overrides are applied depending on the client.
The difference is that we don't use an appSetting, though you could. All of our clients are on the same server, so we manage it using a cookie. When a user signs in, we take the part after the # symbol in their email address and set a cookie corresponding to the client ID. Our CSS overrides are in a folder with the same name as the client ID.
We then have a child action that renders the additional CSS overrides in the head section, based on the cookie value.

ASP.NET MVC website where users can add/remove pages

I'm developing a website for a client, in which they want to be able to manage content and add/remove pages.
At the same time, some pages on the site will be interactive and provide custom reports for logged-in customers.
I've started developing the site in ASP.NET MVC, because I wanted full control over rendering.
However, I'm finding it difficult to conceptually model the site.
If users can add/remove pages, then how can there be a direct mapping of URLs to controllers?
I could do a single 'Page' controller and pass it a content ID, but that would mean that all the code in the site would sit under 1 class file.
I could make the custom/interactive pages sit under different controllers, but then, how will the customer be able to manage them?
I'm really lost with the usability angle of this as well. If I'm building custom interactive pages, how can the client add/remove them anyway? Won't that be modifying the structure of the application itself?
I'm having some problems understanding exactly what you're trying to get at with and what your problem is:
I could do a single 'Page' controller
and pass it a content ID, but that
would mean that all the code in the
site would sit under 1 class file.
I could make the custom/interactive
pages sit under different controllers,
but then, how will the customer be
able to manage them?
What's wrong with "a single class file"? Is your problem from a semantic perspective (ie, you don't want all URLs to begin with /pages)? Or just code management?
Assuming you're serving from a database, I would do the following:
Have a CMSController that accepts requests. It either a) checks the ID (maybe disregarding a stub), or b) takes the stub and looks it up in the db.
Return the content.
That way requests to /CMS/Page/4384 would be served up as you wish. You would then extend this in several ways. Put in a default action, so /CMS/4384 serves up the page. Then add a stub (/CMS/4384/Page-Title-Or-Whatever-Text). Set up additional routes such as /aboutus/ and /product_info/ to all point at your CMSController. Or just have a catchall point to the CMSController.
Also, the controller could open up an html file on the filesystem and serve that.
Does that help at all?
James

Resources