I'm looking to generate custom documentation for a service stack end point. I'm aware of service stack's api for such a thing but the problem is that I have is a have to build a highly customized meta data page that is different depending on the values that are feed into the request:
\myendpoint\1\metadata
\myendpoint\2\metadata
These two urls would generate to totally different sets of metadata pages. Part of the data is procedurally generated so that adds to the complexity as well.
So my question is there an easy way to wire in a custom html page for meta for a specific end point?
Thanks in advance,
Sieg
Please see the documentation on modifying ServiceStack's built-in metadata templates:
The VFS lets you replace built-in ServiceStack templates with your own by simply copying the metadata or HtmlFormat Template files you want to customize and placing them in your Website Directory at:
/Templates/HtmlFormat.html // The auto HtmlFormat template
/Templates/IndexOperations.html // The /metadata template
/Templates/OperationControl.html // Individual operation template
Which you can customize locally that ServiceStack will pick up and use instead.
Using JavaScript to modify links to point to custom pages
As the templates are static html with template placeholders, one approach you could do is to add additional JavaScript behavior to either add links to custom metadata pages (or modify/remove the existing ones).
Related
Using the C# SDK I'm working on a simple application to load a note from evernote, allow the user to edit the note using a HTML wysiwyg editor and then save it back to Evernote.
I'm a little confused. I can load a ENNote from the standard ENSession and access the HTML version of the note, but to update I have to load a Edam.Type.Note which has no HTML properties to set just the standard XML doc.
I can see there is a ENHTMLtoENMLConverter class but its internal? Its counterpart ENMLtoHTMLConverter is public.
Is there an easy to convert basic HTML/ENHTML into a Edam.Type.Note so I can update without writing my own converter or compiling my own version of the SDK?
Creating a note using HTML or web content
The SDK contains a facility for supplying HTML or web content to a
note.
ENNote myFancyNote = new ENNote();
myFancyNote.Title = "My first note";
myFancyNote.Content = ENNoteContent.NoteContentWithSanitizedHTML("<p>Hello, world - <i>this</i> is a <b>fancy</b> note.</p>");
ENNoteRef myFancyNoteRef = ENSession.SharedSession.UploadNote(myFancyNote, null);
This method handles general HTML content, including external style
sheets which it will automatically inline. Please note that this is
not a comprehensive "web clipper", though, and isn't designed to work
fully on all arbitrary pages from the internet. It will work best on
pages which have been generally designed for the purpose of being
captured as note content.
Source : Getting Started with the Evernote Cloud SDK for Windows
You can do this without dipping into the "advanced" stuff. You still want to call ENSession.SharedSession.UploadNote but use the version that lets you specify one of the "replace" policies as appropriate:
public ENNoteRef UploadNote(ENNote note, ENSession.UploadPolicy policy, ENNotebook notebook, ENNoteRef noteToReplace)
You'll still need to create an ENNote with your updated content (you can use the NoteContentWithSanitizedHTML etc). And supply the note ref pointing to the original note you want to replace.
I'm trying to create the sitemap.xml file automatically for my Asp.Net Mvc 5 website. I have installed the MvcSiteMapProvider.MVC5 4.6.1 package from Nuget and I have read the getting started guide. To my understanding I have to add ALL the controllers and their actions to its configuration file. However, somewhere in the doc, it said that the package automatically keeps track of the visited URLs and generates their nodes in the sitemap.xml, "for free"! I visited a few pages and refreshed the sitemap.xml file but it didn't change. Am I missing something? Does this package really provide dynamic sitemap.xml files?
First of all, the \sitemap.xml endpoint is not a "file", it is a controller action that dynamically generates the XML based on the configuration of the SiteMap. It generates the XML to submit to search engines as per sitemaps.org.
Being that this endpoint is for search engines, it doesn't make any sense to keep track of a user's visits on the site and show the pages the user visited in this result. Instead, it contains all of the pages that are configured (either by URL or by controller, action and other route values).
However, the main purpose of MvcSiteMapProvider is to provide menus and breadcrumb trails to individual pages. Again, this doesn't work by tracking a user's position, it works by determining the relative position (in relation to other nodes) of the URL within the SiteMap. For more information, read How to Make MvcSiteMapProvider Remember a User's Position.
You don't necessarily have to add all of the controller actions to MvcSiteMapProvider, technically you only have to add the URLs that you need indexed by search engines. And then you get the sitemaps XML for free.
However, for pages that you don't need indexed (administration pages, for example) it is possible to use a combination of preservedRouteParameters, [TitleAttribute], and ISiteMapNodeVisibilityProvider to fake the breadcrumb trail so you don't have to add a node for every record in the database to make it function, as described in the above article.
I've a question related to dynamic code generation (html) with C# based on a template. The user sets all options (e.g. whether or not a <div> should be displayed, whether or not an image in the template should change by a specific date,...) and provides the content (text, images) needed for code generation. The generated code is needed for a WIFI hotspot site.
The template consists of HTML, CSS and JavaScript which gets extended and modified by the user-defined settings at runtime. I also think of providing "meta settings" in the template to define, whether or not some options CAN be disabled set or not.
My major problem:
How to define the template to dynamically extend the template code easily? For example, if a user option is enabled at runtime, I'm in need to add JavaScript code on top and HTML code below another (specific) place. Another example is to hide content (a defined ) when another option is disabled...
I'm not sure what's the best practice to handle that requirement. Maybe HTML elements with id attribute can help eliminate some of the problems. But with JavaScript I'm not sure. Maybe the template needs to be a XML which creates the final HTML at runtime? Any idea?
Has anyone an idea how to handle that?
UPDATE/INFO:
The project is written in pure C# - without any ASP.NET. It is a desktop project working with HTML files and GENERATING HTML files (as an output).
I suppose you can use ASP.NET MVC Razor view engine to render an html to a file with the help of this question. With Razor you will get the support of dynamic view (aka template) changes, rich template syntax etc. Everything you can do when create a web site. Just render the html to a file not a response body.
We're having a restructuring on our application and currently the idea is to break the codes into Core library codes + customized codes for our developer.
I'm thinking of the possibility to have a folder (i.e. 'custom') that is empty by default, and when the developer need to customize any codes either from existing asp pages or new pages, they just need to put them into the folder and it will work. Example:
Lets say core folder store the default asp pages.
core\customer\createCustomer.asp <-- the default page
And when the developer want to overwrite that page, he needs to copy that asp page to the custom folder, like
custom\customer\createCustomer.asp <-- modified asp page
The application will automatically load the one in the custom folder rather the one in the core folder.
Is this doable in C#?
This MSDN article explains how to use an IHttpModule implementation to intercept HTTP requests and perform custom actions (they point out logging, but since you're intercepting the request you might as well fetch some different content, such as your 'customized' code).
You can use a VirtualPathProvider to load a different file than the "actual requested one". This works well with IIS and caching for instance as well.
Basically you inherit the VirtualPathProvider and override the FileExists, GetFile, and DirectoryExists, GetDirectory methods (there's an example in the linked page). Then, in your AppInitialize, register the provider with
HostingEnvironment.RegisterVirtualPathProvider(sampleProvider);
By the way, don't forget to have a different (non-editable) page so the user can revert any changes that was made, in order to restore a potential misedit so to speak. I would probably have a simple version control system and use commit whenever the user made changes, and allow the user to revert to a previous changeset.
One of the apps I work on is a large ASP.NET 3.5 Web Forms app that is used in the U.S., Central and South Americas, and Europe. We're also starting to do more work with AJAX, and thus we need to settle on a strategy for localizing strings in our JavaScript controls.
For example, we have a control written as a jQuery plugin that formats data into a sortable table. The buttons and table columns need to be localizable.
We're currently using two different approaches to handle this scenario, but I'm not completely satisfied with either.
Write the bulk of the code in a jQuery plugin style, then place a script block on the .aspx page where we'll pull in values from a .resx file and feed them into the plugin code. Here's an example in pseudo code:
<script>
var view;
$(function() {
view = {
columnHeaders: {
productNumber = <%$ Resources:WidgetProductNumber_HeaderText %>,
productDescription = <%$ Resources:WidgetProductDescription_HeaderText %>
}
};
});
</script>
Place the JavaScript in plain .js files with custom tokens in place of strings. We have a handrolled HttpModule that will parse JavaScript files and replace the tokens with values from any existing .resx file whose file name matches the name of the JavaScript file being processed.
Both approaches have problems. I'd prefer to keep our JavaScript code separate from our .aspx pages to make it more unobtrusive and reusable.
The HttpModule approach is clever but a little opaque to developers. I'm also looking to implement a JavaScript bundler called Rejuicer, which is also written as an HttpModule, and getting these to work together seems like it would require customizing the open source code. I'd prefer to use the code as it's written so that we can upgrade it as the project progresses.
Are there any other tried-and-true strategies for approaching this problem in ASP.NET?
It seems that both approaches are a little more complex/cumbersome than necessary. Keep it simple.
1) Using an .ashx, custom http handler, or web service, create a .net object (anonymous, custom -- doesn't matter) that matches the client side JSON object.
2) Populate server side object's properties with the localized values
3) Set the response content type to text/json or text/javascript.
4) Using the JavaScriptSerializer class, serialize the object into the response stream.
From the client side, you have two options:
1) Use an AJAX call to the .ashx/handler/service to set your client side "view" object to the response JSON.
2) Create a script tag with the src="the/path/to/the/serviceOrHandler". In this case you would need to include the js variable declaration in your response output.
Let me know if you need a code sample.
I just stumbled onto this question, and I have another answer to throw into the ring. It isn't my work or anything, but it looks like a fairly elegant solution. It involves writing a localization handler to serve up ASP.NET resources to Javascript. Here are a couple of links:
http://weblog.west-wind.com/posts/2009/Apr/02/A-Localization-Handler-to-serve-ASPNET-Resources-to-JavaScript
http://www.tikalk.com/use-aspnet-resource-strings-within-javascript-files/