SQL Table to SiteMapProvider 4 ASP.net mvc4 - asp.net

I have been trying to use SiteMapProvider from NuGet and make it link to a database in order to get all the links for a sidebar and breadcrumb, so far I don't find any tutorial, and I keep getting stuck using the information to the xml file, I am sure that I have to create a class, but I don't seem to find any tutorial on how to do this, or how to correctly make the call to this class, is there a tutorial or any website that contain this information? I have been trying to do what is included in here:
https://github.com/maartenba/MvcSiteMapProvider/wiki/Dynamic-sitemaps
But I don't know how to define the dynamicNodeProvider, any help? Sorry if it's some what vague what I am asking.. I have tried to search but I haven't find any information..
EDIT:
I was able to load information using :
[MvcSiteMapNode(Title = "HOLDCREATEREPORT", ParentKey = "Home", Key = "CreateReport")]
on each, class, but I am more interested in doing this using a unique class that loads all nodes, I have tried so far to change the sitemap xml to the following code:
navigation itself has the following code:
public class navigation : DynamicNodeProviderBase
{
public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
{
for (int i = 0; i < 20; i++)
{
DynamicNode dynamicnode = new DynamicNode();
dynamicnode.Title = "test"+ i.ToString();
dynamicnode.ParentKey = "Home";
dynamicnode.RouteValues.Add("test" + i.ToString(), "abcdb"+ i.ToString());
yield return dynamicnode;
}
}
}
yet when I run it nothing gets displayed, I am pretty sure I am missing something extremely easy >_>.

Dynamic Node Providers require a definition node. The definition node can either be in XML or as a .NET attribute. It won't be included in the SiteMap, but the nodes that the Dynamic Node Provider create will be.
[MvcSiteMapNode(Title = "Dynamic Nodes", DynamicNodeProvider = "MyNamespace.navigation, MyAssembly")]
Or
<mvcSiteMapNode title="Dynamic Nodes" dynamicNodeProvider="MyNamespace.navigation, MyAssembly">

Related

Render Node by Id in Umbraco 4.11

TL;DR How do you render a content item by Node Id.
I'm using Widget Grid admin extension for Umbraco to configure a content manageable widget area and I'm stuck trying to render the configured widgets.
I have a list of node id's that I want to render on the page but I can for the life of me work out how to do this.
Any guidance is greatly appreciated! Thanks.
UPDATE
Xml contained within the Models property
<WidgetGrid>
<col1> <nodeId>4839</nodeId> <nodeId>4844</nodeId> <nodeId>4845</nodeId> </col1>
</WidgetGrid>
Once I get down to col1 it seems to cease being of type DynamicXml and just spits it out as a string... No idea.
Presumably you're doing this from within a macro, and I'm going to presume you have a multi-node picker set to store the Id values as CSV:
#{
string[] widgetIds = ((string)Model.Widgets).Split(',');
foreach (var id in widgetIds)
{
var widget = Model.NodeById(id);
#RenderPage("~/macroscripts/widgets/" + widget.NodeTypeAlias
+ ".cshtml", widget);
}
}
This will let you select different types of widget in your multi-node picker, and have a different view for each widget.
This also uses the dynamic approach but you could easily adapt this by swapping the first line for:
string[] podIds = CurrentModel.GetProperty<string>("widgets").Split(',');
Given that the property is stored as XML, you can use the notation as described in this post (http://umbraco.com/follow-us/blog-archive/2011/2/28/umbraco-razor-feature-walkthrough-%E2%80%93-part-3):
foreach (var id in Model.widgets.col1[0].nodeId)
{
...
}

Alfresco Object is not available in extension module in alfresco share

I am trying to override the javascript controller node-header.js of components\node-details with the extension module of alfresco share
This is my node-header.get.js
<import resource="classpath:/alfresco/templates/org/alfresco/import/alfresco-util.js">
for (var i=0; i<model.widgets.length; i++)
{
if (model.widgets[i].id == "NodeHeader")
{
if(model.widgets[i].options.nodeRef!=null)
{
var jsNode = new Alfresco.util.Node(model.widgets[i].options.nodeRef);
if(jsNode.hasAspect("custom:intranetFile")){
model.widgets[i].options.showFavourite = false;
model.widgets[i].options.showLikes = false;
}
}
}
}
I am getting this error
Error Message: 05270002 Failed to execute script
'classpath*:webscripts/custom/nodeheader/hidelikesync/node-header.get.js':
05270001 ReferenceError: "Alfresco" is not defined.
(jar:file:/C:/Alfresco/Alfresco42/tomcat/webapps/share/WEB-INF/lib/customshare.jar!/webscripts/custom/nodeheader/hidelikesync/node-header.get.js#1555)
Error lies in this line
var jsNode = new Alfresco.util.Node(model.widgets[i].options.nodeRef);
as Alfresco object is not available how can I get it?
Based on my answer yesterday on the share-extras-devel list:
Your issue is that you are mixing up your web script JS with client-side JavaScript. Alfresco.util.Node is a client-side helper class and is therefore available to client-side JS running in the web browser, but not to your web script code which runs on the server.
If you look at the source of alfresco-util.js, which you are including, you will see that there is a helper class there but it is called AlfrescoUtil.
To get some information on this given node I would suggest that you want to use the static method AlfrescoUtil.getNodeDetails() from that class, e.g.
var jsNode = AlfrescoUtil.getNodeDetails(model.widgets[i].options.nodeRef);
The structure of the jsNode object will be as per the JSON returned by the doclist-v2 webscripts, so you should be able to check for the presence of your custom aspect in the aspects array property.
If you check the source of alfresco-util.js you will see that additional parameters are also supported by getNodeDetails(). It seems to me you can also pass in an optional site name, plus some options if you wish.

Dynamic sitemap, database driven

I've been struggling with this for a couple of days now. Can't find any good example, or an example that I understand.
Background:
I own a small blog platform for user to blog.
Each user gets their own subdomain and for now there is no sitemap available. Not good.
I want to create some kind of dynamic sitemap, where all sitemapnodes is retreived from the database. The sitemap will be used only for the search engine spiders.
System: ASP.NET, mySQL.
The sitemap is pure XML. So I need in some way to create an ASPX file that return xml-data instead of html.
And I need to somehow redirect the web.sitemap to that dynamic file.
I have never worked with XML, and I dont know how to create a file that creates XML data. So i dont even know what to search for.
I don't want any static sitemap file to be stored on the server. Everything should be created on the fly.
So. Please. If you can give me some advise about XML, any example on the internet, or just what to search for.
My main questions:
1.
How to create XML output from aspx file?
2.
How do I "inform" the system, and search engine crawlers that the file to crawl is "/sitemap.aspx"
ThankS!
I looked into MvcSiteMapProvider.MVC5 and I could not get it to work. First of all it modified my Web.config to the point that my css and js files were getting a 404 not found when running my web app.
With the time I spent getting MvcSiteMapProvider to work I could have just wrote my own.
So... here is my own dumbed down version of generating a sitemap xml.
The only thing is you have to specify your routes manually. I haven't added reflection yet to go through each controller and pull out each action.
The data-driven piece works very well though.
In your Home controller add the action Sitemap and the private helper methods.
GetRouteUrls is the manually added controller/action routes.
GetDynamicUrls builds the data-driven Urls. In my example I have a LiquidsController and a Details(string id) action.
public ActionResult Sitemap()
{
var xml = new XDocument(
new XDeclaration("1.0", "utf-8", null),
new XElement("urlset",
new XAttribute("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9")
, GetRouteUrls()
, GetDynamicUrls()
)
);
return new XmlActionResult(xml);
}
private List<XElement> GetDynamicUrls()
{
var result = new List<XElement>();
using (var db = new ApplicationDbContext())
{
var liquids = db.Liquids.ToList();
foreach (var liquid in liquids)
{
result.Add(LocUrl("Liquids", "Details", liquid.FriendlyId));
}
}
return result;
}
private List<XElement> GetRouteUrls()
{
var result = new List<XElement>();
result.Add(LocUrl("Account", "Register"));
result.Add(LocUrl("Account", "Login"));
result.Add(LocUrl("Home", "Index"));
result.Add(LocUrl("Home", "About"));
result.Add(LocUrl("Home", "Contact"));
result.Add(LocUrl("Home", "TermsOfService"));
result.Add(LocUrl("Home", "PrivacyStatement"));
result.Add(LocUrl("Liquids", "Index"));
result.Add(LocUrl("Vendors", "Index"));
result.Add(LocUrl("Hardware", "Index"));
return result;
}
private XElement LocUrl(string controller, string action, string id = null)
{
if (!string.IsNullOrEmpty(id))
action = string.Format("{0}/{1}", action, id);
var baseUri = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~"));
return new XElement("url",
new XElement("loc", string.Format("{0}{1}/{2}", baseUri, controller, action))
);
}
I then added a route so I could access the sitemap doing /sitemap
routes.MapRoute(name: "sitemap", url: "sitemap", defaults: new {controller = "Home", action = "Sitemap"});
The XmlActionResult return type can be found here:
Return XML from a controller's action in as an ActionResult?

Javascript permission denied error when using Atalasoft DotImage

Have a real puzzler here. I'm using Atalasoft DotImage to allow the user to add some annotations to an image. When I add two annotations of the same type that contain text that have the same name, I get a javascript permission denied error in the Atalasoft's compressed js. The error is accessing the style member of a rule:
In the debugger (Visual Studio 2010 .Net 4.0) I can access
h._rule
but not
h._rule.style
What in javascript would cause permission denied when accessing a membere of an object?
Just wondering if anyone else has encountered this. I see several people using Atalasoft on SO and I even saw a response from someone with Atalasoft. And yes, I'm talking to them, but it never hurts to throw it out to the crowd. This only happens in IE8, not FireFox.
Thanks, Brian
Updates: Yes, using latest version: 9.0.2.43666
By same name (see comment below) I mean, I created default annotations and they are named so they can be added with javascript later.
// create a default annotation
TextData text = new TextData();
text.Name = "DefaultTextAnnotation";
text.Text = "Default Text Annotation:\n double-click to edit";
//text.Font = new AnnotationFont("Arial", 12f);
text.Font = new AnnotationFont(_strAnnotationFontName, _fltAnnotationFontSize);
text.Font.Bold = true;
text.FontBrush = new AnnotationBrush(Color.Black);
text.Fill = new AnnotationBrush(Color.Ivory);
text.Outline = new AnnotationPen(new AnnotationBrush(Color.White), 2);
WebAnnotationViewer1.Annotations.DefaultAnnotations.Add(text);
In javascript:
CreateAnnotation('TextData', 'DefaultTextAnnotation');
function CreateAnnotation(type, name) {
SetAnnotationModified(true);
WebAnnotationViewer1.DeselectAll();
var ann = WebAnnotationViewer1.CreateAnnotation(type, name);
WebThumbnailViewer1.Update();
}
There was a bug in an earlier version that allowed annotations to be saved with the same unique id's. This generally doesn't cause problems for any annotations except for TextAnnotations, since they use the unique id to create a CSS class for the text editor. CSS doesn't like having two or more classes defined by the same name, this is what causes the "Permission denied" error.
You can remove the unique id's from the annotations without it causing problems. I have provided a few code snippets below that demonstrate how this can be done. Calling ResetUniques() after you load the annotation data (on the server side) should make everything run smoothly.
-Dave C. from Atalasoft
protected void ResetUniques()
{
foreach (LayerAnnotation layerAnn in WebAnnotationViewer1.Annotations.Layers)
{
ResetLayer(layerAnn.Data as LayerData);
}
}
protected void ResetLayer(LayerData layer)
{
ResetUniqueID(layer);
foreach (AnnotationData data in layer.Items)
{
LayerData group = data as LayerData;
if (group != null)
{
ResetLayer(data as LayerData);
}
else
{
ResetUniqueID(data);
}
}
}
protected void ResetUniqueID(AnnotationData data)
{
data.SetExtraProperty("_atalaUniqueIndex", null);
}

how to create google sitemap for mvc site?

I was wondering if anyone has done this yet or has any examples
on how to create a Google Sitemap for an MVC website.
Any help or example would be appreciated.
Im talking about this:
https://www.google.com/webmasters/tools/docs/en/protocol.html
I used Mike Brind's Sitemap code, with a small change.
You need to add the XNamespace to every XElement, otherwise Google spits the dummy.
Here's my version:
public ContentResult Index()
{
XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9";
const string url = "http://www.website.com/controller/action/{0}";
var items = _db.DataAccessHere();
var sitemap = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement(ns + "urlset",
from i in items
select
//Add ns to every element.
new XElement(ns + "url",
new XElement(ns + "loc", string.Format(url, i.ItemID)),
new XElement(ns + "lastmod", String.Format("{0:yyyy-MM-dd}", i.DateAddedUTC)),
new XElement(ns + "changefreq", "monthly"),
new XElement(ns + "priority", "0.5")
)
)
);
return Content(sitemap.ToString(), "text/xml");
}
Credit to Mike for posting the original article and code.
Shameless self plug: I created a library called SimpleMvcSitemap after having weird issues with MvcSiteMapProvider on production. You can serve sitemap files from any action method without any configuration:
public class SitemapController : Controller
{
public ActionResult Index()
{
List<SitemapNode> nodes = new List<SitemapNode>
{
new SitemapNode(Url.Action("Index","Home")),
new SitemapNode(Url.Action("About","Home")),
//other nodes
};
return new SitemapProvider().CreateSitemap(nodes);
}
}
It also supports all the Google Sitemap extensions available.
The easiest way would be to use any one of a number of free sitemap builders out there - they will crawl your site, follow links, and generate a sitemap XML file for you.
Here's one for example
Here's a post that might give you some ideas. Basically it generates a sitemap from route values.
so here's the thing, using generators will just about create a link for "everything" in your site. So if you have, let's say a card site, and you have like a hundred thousand card items, each with it's own link and all, you'll likely see the same amount of links. If you want that, then xml sitemap generators are the way to go.
But if you want it a little bit personalized, you can do these:
List all major sections of your sites. This is easy to do considering that most MVCs are using the "clean URLs" sort of thing. kinda like "site.com/items/phones"
Create an XML document, depending on the language you're using.
At the minimum, you should have a document like this:
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://dragonflysco.com/catalog/finishings/19</loc>
</url>
<!-- more here -->
</urlset>
For more advanced structure, check this:
http://www.google.com/support/webmasters/bin/answer.py?answer=183668

Resources