Bread crumbs with url rewriting - c#

In database I have a list of hierarchical list of categories so i construct a Custom Sitemap provider (by extending StaticSiteMapProvider ) with this list of categories.
Now, the page that display articles /ShowArticle.aspx?id=" + Eval("ID") is rewrited into:
/id/article-title.aspx.
So it's not physical exists.
I want the following: When the selected page is displayed I want to display the complete category path in the "Bread crumbs" (every article has a "category" property that contains it's 1 lvl category - without parents)
For example categories structure:
Home
Products
CdRom
DvdRom
Toshiba
Support
Hardware
Software
When an article id=xx,category=Toshiba, title="Best Toshiba DVD" is opened, the path in "Bread crumbs" should be:
Home|Products|DvdRom|Toshiba|Best Toshiba DVD
How to do it? Should I add something to my custom Sitemap provider?

I don't get any answers :(
Maybe I should do like this:
Instead constructing the site map for categories, i should construct it both for categories and all available articles in the database.
It's not efficient (even with caching), but it's the only way i think.
What else can I do?
Update:
What is left is just to create dynamically list of links that will act as bread crumbs,
when an article is opened it's containing category will be read and full hierarchical categories path will be calculated (from root to this current node).

I had to look up what the SiteMap provider was, and in doing so accidently came across the answer you may be looking for on the MSDN website: Breadcrumb using SiteMapPath Class
It might not be quite what you are after but it could be a point in the right direction :)

Related

Umbraco site wide settings node

I am working with Umbraco and was wondering whether there is a easy way to create a site wise settings node.
At the moment I have this tree structure.
Content
Home
Item 1
Item 2
Item 2a
What I would like to create is something like this
SITE WIDE CONTENT
Content
Home
Item 1
Item 2
Item 2a
Site Wide Content will contain something like Google Analytics Url, that the user can change easily.
Is there a way to accomplish this?
EDIT: See bottom for a method for handling page redirects and 404 errors resulting from templateless nodes...
A common node structure may look like this which allows for site specific content - the advantage here is that all the site content resides under the home node and users can't create more content in the root (provided you've set things up properly):
Home [Contains Settings Tab]
Page 1
Page 2
Contact Us
About
Depending on how much site wide settings information, you could create a Settings tab on the Home DocumentType and store it all there (as illustrated above); or create a tree structure using a Settings node (as illustrated below):
Home
Page 1
Page 2
Contact Us
About
Settings [has General Settings tabs/properties]
Email Templates [Store other nodes that represent mail merge template for example]
Alternatively, for Global Settings/Content (where I might have multiple sites) I frequently create a separate node structure at the root to contain global settings, email templates, etc.:
Home
Page 1
Page 2
Contact Us
About
Settings [has GlobalSettings tabs/properties]
Email Templates [Store other nodes that represent mail merge template for example]
Create a Settings DocumentType to act as a folder or container, but don't give it a template and all your global/site-wide settings/data content can be organised under that.
Handling Nodes without Templates
DocumentTypes that are created without assigning/creating a Template for them (as in the case of say the Section node at the base level of the tree and it's children) will throw a 404 error when someone attempts to visit it's URL, and thus should be excluded from any navigation rendered in the website. Any user manually entering the URL that you would expect to find the node at, e.g. /settings will be presented with the default 404 error page as it doesn't exist.
There are a few ways to mitigate this:
Add a property to the DocumentType with the alias umbracoRedirect and using the ContentPicker DataType;
Create a custom 404 Error page and set up the Umbraco configuration to use that instead of the default.
If you use the first option, you can set the page that you want the user to see by default - generally the Home page.
The second option can be good if you have some custom logic (like finding closest matching page based on URL) in your 404 error page, or use something like SEO Checker to handle 404 errors and redirects for you.
A lot of this is mitigated by simply making sure those nodes aren't visible via their URL in the website at all, which can be done by coding your navigation structures (menu's, sitemaps, etc.) to exclude them.
Note: I generally make sure they are also excluded by any sitemap.xml generators so that search engines don't attempt to index them. You can also add them to your robots.txt files as well.

How would I implement tags within a database?

I have an app and I want users to be able to add tags to articles (similar to stack overflows tags) but I want it to be dynamic. So far I have it as JSON strings (dont squirm too much) but this has a major shortcoming. Firstly I will show you an example, and then explain my problem.
Say I have an article and it's on bees, so users tag: bees, insect, honey, outdoors.
Then in my article class (entity framework) I have
string AssosciatedTags { get; set; }
which would hold: "[\"bees\", \"insect\",\"honey\"]"
then when I render the article I just do in javascript:
JSON.parse(model.AssosciatedTags);
and do whatever I want ... add/remove tags with ease. Ok, so here's where I didn't really think enough, and now I have I still am rather confused. How can I implement a sorting mechanism? Let's say my users are bee crazy. They love bees. Their cute little black and yellow stripes. So they want to click tags they are interested in and my server returns articles that have those tags assosciated.
But how? If I have lots of articles, it seems a bad idea to parse all tags from JSON to an array, look for this tag and return those articles.
My other consideration is to simple to a lookup for ",tagName," which is pretty filthy.
Is there a standard way or one that is hopefully more optimal.
My other consideration is to simple to a lookup for ",tagName," which is pretty filthy.
Yes, that is filthy. This technique has it's place but not here.
Store the tags in another table with the schema int ArticleID, string TagName. That way you can index TagName and query it efficiently.
This is the standard solution.
If you want to you can keep the JSON string but you need to keep it in sync with the table storing the tags. Preferably remove it, or be very careful.
Don't store your tags as JSON. Parsing them will be a huge slowdown on your database. Split them up into their own table. Something like this:
articles <--- table of articles
tags <--- table of tags
articles_tags <--- join table that associates articles with tags
This is called a Many-to-Many relationship.

How do I create an mvcsitemap that displays a dynamic name

Really struggling with this and not finding much helpful stuff on google.
I set up a sitemap, and I want some breadcrumbs such that url:
/CatManagement/Cats/38
displays breadcrumbs
Cat Management > Cats > Mr. Fuzzy Wuzzy
I don't quite understand what the sitemap node structure would be for this as the 38 is sort of a parameter of Cats.
In the dynamicNodeProvider I created I can probably grab the ID somehow and do a quick lookup to get the name, but I am not sure how to bring it all together.
Any ideas?
Have a look at Routing Basics in the MvcSiteMapProvider wiki. You just need to ensure that your parameter (38) is preserved from the current request, the node matching logic already takes into consideration action method parameters. That example shows how you would do that using a custom dynamic node provider, but I recommend reading the entire document as understanding it is key to making MvcSiteMapProvider work.
I have also created a more in depth look at the problem here with working demos for download: http://www.shiningtreasures.com/post/2013/09/02/how-to-make-mvcsitemapprovider-remember-a-user-position

query a website and retrive public data from it

I am really new in c# programming. I would like some help from you guys (if possible). I have a website (it is a shopping website ) with data : products, price, description...etc. What I would like to do is: Since the website has a search capability so I would like to get the data from it by querying the search link and get only the important data (product id, name, price and description). When I perform the search I get many pages, and every time I press next I get new page with extra list of products. How can I simply make automation of these tasks?
I searched a lot over internet I found that I need to use webclient() with regular expression, and I thought that maybe a loop over the page content and over the search result pages would be necessary.
what do you think guys?
Website Example.
I´ll appreciate any effort from your side.
What you're describing is called scraping.
What you'll want is to use something like HtmlAgilityPack to get the website. Then you find the nodes you're interested in by using the DOM, and reading their inner text.
The whole process is rather complicated, but at least I've sent you off in the right direction. For the most part, search urls tend to have the same format.
In your link for instance
http://cdon.se/hemelektronik/advanced-search?manufacturer-id=&title=.&title-matchtype=1&genre-id=&page-size=15&sort-order=142&page=2
You can change 'page' to be smething else and you can go through all the pages that way.
Added:
Also don't TRY to use regex to parse html. It drove one particular person mad...
RegEx match open tags except XHTML self-contained tags

Custom navigationprovider in sharepoint - how to generate the navigation items from a list?

thank you for reading my question.
Following situation:
-A sharepoint list, based on a custom content type. The content type is nothing more than a folder with some extra properties (like url, targetpage).
-The folder content types and items represent a menu structure. For example:
Home | www.home.com | home.aspx
---> Subhome | www.subhome.com | subhome.aspx
Impressum | www.impressum.com | impressum.aspx
This structure has no limits how deep it's going to be or how many items/folders it can contain. The only restriction is that inside a folder every name must be unique.
Because of the performance I need to fetch all items in the list at once and not for every folder. I managed it this way:
SPQuery qry = new SPQuery();
qry.ViewAttributes = "Scope='RecursiveAll'";
After that I translate the SPListItems into an object called NavigationEntry. This object contains an SiteMapNode and some other properties like the path, itemname and levelcount (e.g. Home/Subhome = level2, Impressum = level1).
Now I place all this items in a dictionary with the path+itemname as key (because it's unique and gives me a hint where the item lies). After that I access this dictionary with linq and grab the items level per level until I reach the end (no items available on a level). Now comes the tricky part. I have to "convert" this weird structure into navigation structure for sharpoint. Because i'm new to sharepoint this is a bit confusing sometimes.
At the moment I go trough the levels and create SiteMapNodes with SiteMapNodeCollections, go to the next level, look if the parentitem is already there, put the child into it and so on. That works, but its very complicated, dirty and fragil.
Is there any "easy" or more structured way to solve this issue? I'm not looking for an already coded solution but for any hint into the right direction on how to solve this. Thank you! :)
IF just an Navigation tree is what you want , I can recomment JSTree
I once used it for a multilevel Quichnav Delegate. While I made a Manage Interface to add items, You could just cunstruct a XML or Json in the Change Events of the List. Or to be more fancy do a query every time a node is expanded.
Hope this helps
Lars

Categories

Resources