Umbraco Architecture with query string parameters for document - c#

I have a client web app that I've been asked to make some updates to. I have a small number of development hours to work within so a redesign of the system is not an option at this time.
The app was written using classic asp with logic to pull certain content dynamically from a custom database and to write back certain user actions to the same custom database. There is an admin area for viewing these logged user actions.
At some point in time portions of the web app were migrated to use Umbraco 4 for the cms. I've been tasked with migrating some additional content, that is still being pulled from the original custom database, into the context of the CMS.
The content in question is structured so that the content node's document type points to a special masterpage. The master page has codebehind logic that checks for a query string parameter and uses that parameter to query the database for content specific to that parameter. In then populates one specific section on the page with that content.
The logic also uses the query string parameter when writing user actions back to the custom database.
I need to maintain the url syntax and behavior of writing user actions back to the custom database but move the displayed content specific to that parameter into the CMS somewhere. Where should I place this content in the CMS and how can I access it from those pages via the query string parameter?
Url Examples:
/site_home/Node1/Node2/Node3/
/site_home/Node1/Node2/Node3/?partner=partner1
/site_home/Node1/Node2/Node3/?partner=partner2
/site_home/Node1/Node2/Node3/Review/
/site_home/Node1/Node2/Node3/Review/?partner=partner1
/site_home/Node1/Node2/Node3/Review/?partner=partner2
/site_home/Node1/Node2/Node3/Checkout/
/site_home/Node1/Node2/Node3/Checkout/?partner=partner1
/site_home/Node1/Node2/Node3/Checkout/?partner=partner2

If you can provide a bit clearer explanation of what you are trying to accomplish, I am sure that I can assist you further. However, the code below and link to the discussion from which I pulled it may help get you on the path. Give me some feedback or edit your question and I will edit my answer to assist.
#{
if(!string.IsNullOrEmpty(Request.QueryString["query"]))
{
int result= 0;
if(Int32.TryParse(HttpContext.Current.Request.QueryString["query"].ToString(), out result))
{
umbraco.MacroEngines.DynamicNode node = new umbraco.MacroEngines.DynamicNode(result);
<h1> #node.Name </h1>
}
else
{
<h2>No query found</h2>
}
}
}
Umbraco Forums - Render Node content from querystring

Related

How to design ASP.NET Core - SQL application where user should be able to create forms of different input items and store values in database

I've started working on a web application project, where a feature is: the admin user can create/update few custom forms choosing different input types from the database and the end users can update the form data in a repetitive fashion/sometimes daily and the data stores in the database for further use cases. To elaborate, the admin user can choose any of "checkbox", "textbox", "textarea", "datetime", "temperature" etc. input types and create a form. The end user then can read the form and input the values that is to be saved in the database for reporting to admin.
I need to use ASP.NET Core MVC, SQL, EF, code first migration at the back-end of the project.
I am thinking maybe (as an example) a Form model with Id and Name properties, TextBox model with Id, Name, FormId, DateTime model with Id, Name, FormId etc. for creating the forms and then when user inputs values that can be updated using other models/tables in the database like TextBoxRecord model with Id, TextBoxId, Value, UserId, DateEntered etc. But then it will be too many tables to update and read every time when entering values and displaying reports to the admin.
I appreciate any help with a good design idea of the data model or how to attain this kind of logic. Also feel free ask, if you have any questions. Thanks.
Some time ago, I was working on some simular project. We don't store each of our form field in DB, because we don't want to update DB each time we need to add some new-kind-of-form-field. We believe it's up to HTML+JS to decide what kind of input to use with particular object property.
We create a serializer, that serialize form structure in xml and store it in DB. In this xml we keep a TableName (EF DataSet<> name) and ColumnName (name of model property) for each FormField.
When we need to show a form to user, we deserialize it from DB, pack in ViewModel (because we don't want to show to user real names of our DB tables) and send it to JavaScript code as JSON. JS then constructs the form element and show it to user. When user submits the data, we again deserialize corresponding form from DB and update actual models in db with data from user input.
Hope this will help.
To all the, eurhm, people, who find this an interesting question and "would like to know the answer too", there's an interesting article to read at
https://www.red-gate.com/simple-talk/opinion/opinion-pieces/bad-carma/
That story started with (at least as good as) exactly the same kind of user requirement as the OP's here.
(And to those who want to downvote this because "not an answer" : it is MORE of an answer because it shows in intimate detail WHY you NEVER want to even start going down that alley.)

How can I hold data through multiple Web pages

Starting at WebPage1, the user enters some data into a textbox and performs a search based on that search data. Then the user navigates away from WebPage1 to WebPage2 via a link.
How can I maintain their original search data when the user returns to WebPage1?
The user does not want to see the data in a query string. However the data is not sensitive, and any data from the client will be handled before processing.
We are using C# Mvc framework with Razor.
I have been trying to Post the entire model each time rather than using Get requests. However, this is not working well and does not follow a simple Post-Redirect-Get pattern more like Post-Redirect-Post.
You can use sessions to pass data from one webpage to another until you close the browser here is an example
//assuming the method below will return list of Products
var products=Db.GetProducts();
//Store the products to a session
Session["products"]=products;
//To get what you have stored to a session
var products=Session["products"] as List<Product>;
//to clear the session value
Session["products"]=null;

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.

Rendering Dynamic asp.net webpage into string invoked from another page

The question basically drill's down to these two C# 2.0, ASP.NET 2.0 webpages.
viewtemplate.aspx
generatetemplate.aspx
Purpose of these:
viewtemplate.aspx - Displays Email template defined in 'generatetemplate.aspx', with client assigned data pulled from database
generatetemplate.aspx - Is the actual page that contains place holders for client to put data.
[i named it so because that's the file i will be generating email to be sent from]
Requirement:
I will be requesting the generatetemplate.aspx from viewtemplate.aspx
, get the rendered output of generatetemplate.aspx and then send that output as email to the recipients.
It is the rendering part which i don't know how to do.
Note:
I will be calling generatetemplate.aspx from viewtemplate.aspx with query string so that generatetemplate.aspx will Pull value from database and then render rather than rendering with default values
You wish to get the rendered HTML output of running the page? You can download it from an HTTP request like a browser would with the WebClient class.
string generated = new WebClient().DownloadString("generatetemplate.aspx?myparams=params");
"generated" will then contain rendered output that you can do whatever you like with.
if I got question right, this is looks dodgy a bit.
I've used XSL + XML for such case. So you just prepare data in XML format, than applying XSL layout and thats it.

Can I pass a .net Object via querystring?

I stucked at a condition , where i need to share values between the pages. I want to share value from Codebehind via little or no javascript. I already have a question here on SO , but using JS. Still did'nt got any result so another approach i am asking.
So I want to know can i pass any .net object in query string. SO that i can unbox it on other end conveniently.
Update
Or is there any JavaScript approach, by passing it to windows modal dialog. or something like that.
What I am doing
What i was doing is that on my parent page load. I am extracting the properties from my class that has values fetched from db. and put it in a Session["mySession"]. Some thing like this.
Session["mySession"] = myClass.myStatus which is List<int>;
Now on one my event that checkbox click event from client side, i am opening a popup. and on its page load, extracting the list and filling the checkbox list on the child page.
Now from here user can modify its selection and close this page. Close is done via a button called save , on which i am iterating through the checked items and again sending it in Session["mySession"].
But the problem is here , when ever i again click on radio button to view the updated values , it displays the previous one. That is , If my total count of list is 3 from the db, and after modification it is 1. After reopening it still displays 3 instead of 1.
Yes, you could but you would have to serialize that value so that it could be encoded as a string. I think a much better approach would be to put the object in session rather than on the URL.
I would so something like this.
var stringNumbers = intNumbers.Select(i => i.ToString()).ToArray();
var qsValue = string.Join(",", stringNumbers);
Request.Redirect("Page.aspx?numbers=" + sqValue);
Keep in mind that if there are too many numbers the query string is not the best option. Also remember that anyone can see the query string so if this data needs to be secure do not use the query string. Keep in mind the suggestions of other posters.
Note
If you are using .NET 4 you can simplify the above code:
var qsValue = string.Join(",", intNumbers);
Make the object serializable and store it in an out-of-process session.
All pages on your web application will then be able to access the object.
you could serialize it and make it printable but you shouldn't
really, you shouldn't
The specification does not dictate a minimum or maximum URL length, but implementation varies by browser and version. For example, Internet Explorer does not support URLs that have more than 2083 characters.[6][7] There is no limit on the number of parameters in a URL; only the raw (as opposed to URL encoded) character length of the URL matters. Web servers may also impose limits on the length of the query string, depending on how the URL and query string is stored. If the URL is too long, the web server fails with the 414 Request-URI Too Long HTTP status code.
I would probably use a cookie to store the object.

Categories

Resources