does Server.CreateObject("Microsoft.XMLDOM") use activex? - asp-classic

im planning on using asp classic to create an XML file for users to download, however i am not able to do this via activex. upon checking around, i noticed that one of the more common statements is
Server.CreateObject("Microsoft.XMLDOM")
does it use activex?

Ultimately "ActiveX" is just some marketing spin for COM components. (Putting X on the end of words back then is the same as putting i at the start of words today)
However over time ActiveX has become associated more with control components, COM components that have some UI, which clearly you can't use server-side.
The place to start is with
Dim xml: Set xml = CreateObject("MSXML2.DOMDocument.3.0")
This is a COM object so strictly speaking it is an ActiveX component however as with other components like ADODB it works fine in server side code like ASP

Related

Culture-specific XAML workflows in Windows Workflow 4.0

I've created a simple XAML workflow with a single InArgument with a default value of 1.234. If I then switch my machine to French(France) in Regional and Lanaguage Options and try to load the workflow into the VS design view, I get the error:
'Failed to create a 'InArgument' from the text '1.234'.'
Looking at the XAML I can see that the attribute this:Activity1.arg1="1.234", which is causing the problem. I then tried creating an equivalent XAML workflow from scratch using VS whilst still running under French settings, and the resulting XAML is different - the attribute is this:Activity1.arg1="[1.234]".
This is causing me two problems:
1) Our end users will not be able to send XAML files to other users running under different regional settings
2) The two XAML files deserialise to different object graphs - in the first case I end up with a Literal and in the second case I get a VisualBasicValue. I then need to code around the differences when I am manipulating the workflow programmatically.
Is there some simple way to avoid this by ensuring that the XAML is always written/read in a neutral culture?
You can programatically change the Thread.CurrentCulture to the invariant culture. This can be done temporarily, while the workflow is being loaded.

Include ASP.NET pages from C#

In a typical web framework
func viewHomepage()
response.write(template.render("a string variable", ["an", "array"]))
is a fairly standard way of calling a templating engine and writing the output out.
Obviously the situation is reversed in ASP.net, since the templating engine sits in front of the code.
I am dealing with a legacy application that can't be rewritten. It's basically a 50 line xxx.aspx with a corresponding 20,000 LOC xxx.aspx.cs. What I want to do is write new "views" as separate ASP.net forms and controls and then include them back into the
xxx.aspx.cs.
Essentially instead of doing:
case "newfeature":
{
Response.Write("<table>");
...
Response.Write("</table>");
}
break;
I want to do
case "newfeature":
Response.Write(THEFUNCTIONIMLOOKINGFOR("newfeature.aspx"));
break;
That way there'll be some notion of modularity and it won't be reminiscent of a perl CGI script.
Show me a path to sanity pretty-please.
This can be done quite simply by calling the RenderControl method. You just need to pass it an HtmlTextWriter instance.
The technique is described here: 4GuysFromRolla.com "Emailing the Rendered Output of an ASP.NET Web Control"
There's also the MSDN Reference for the RenderControl method.

unrecognizable code in classic ASP; need .NET conversion

oXML = Server.CreateObject("Msxml2.DOMDocument.4.0")
oNode = oXML.createElement("CommonCustomerSearch")
can someone explain what the lines of code above are doing? i'm more interested in the first line as the method it is written in exits when it hits that line, so apparently the variable oXML isn't being set. i know that oXML is supposed to be set to some kind of COM object but can you explain the "Msxml2.DOMDocument.4.0" part a bit more? what is that, where is that, and what will it look like in .NET (this code is a classic asp)? i don't know what the second line of code above is either but the method never even reaches it so if you have any ideas about what that is doing would be great too. thanks
That is code using the old MSXML COM object. The XML namespace in .NET will do almost the exact same thing, using similar syntax. And bypass COM (a good thing). Convert these statements to use .Net's XML.
Msxml2.DOMDocument.4.0 is the COM object name.
If the createobject is existing the method, then something is probably wrong.
In .net you can say, like, Dim MyXMLDocument as New XML.XMLDocument, etc.
That classic ASP code is making use of the XML DOM library. The first line (if properly coded with the set keyword) creates an XML document in memory. The second line creates an XML node named CommonCustomerSearch.
.NET Framework 3.5+
If you want to move to .NET 3.5 or later, you could do the same thing with System.Linq.Xml
var xmlDoc = new XDocument(new XElement("CommonCustomerSearch"));
You can read the Getting Started Guide for LINQ to XML for more info.
.NET Framework 2.0
It sounds like you're limited to .NET 2.0, so you can use System.Xml to accomplish this in a less sexy way.
XmlDocument doc = new XmlDocument();
doc.LoadXml("<CommonCustomerSearch/>");
The Msxml2.DOMDocument.4.0 is a COM object and the line is supposed to create an instance of the class. I donĀ“t know if this is all the code but you are required to use the Set keyword when initializing an instance of an object. So it should in fact be
Set oXML = Server.CreateObject("Msxml2.DOMDocument.4.0")
Set oNode = oXML.createElement("CommonCustomerSearch")
The Msxml class is an abstraction of an xml document.

Applying Unity in dynamic menu

I was going through Unity 2.0 to check if it has an effective use in our new application. My application is a Windows Forms application and uses a traditional bar menu (at the top), currently.
My UIs (Windows Forms) more or less support Dependency Injection pattern since they all work with a class (Presentation Model Class) supplied to them via the constructor. The form then binds to the properties of the supplied P Model class and calls methods on the P Model class to perform its duties. Pretty simple and straightforward.
How P Model reacts to the UI actions and responds to them by co-ordinating with the Domain Class (Business Logic/Model) is irrelevant here and thus not mentioned.
The object creation sequence to show up one UI from menu then goes like this -
Create Business Model instance
Create Presentation Model instance with Business Model instance passed to P Model constructor.
Create UI instance with Presentation Model instance passed to UI constructor.
My present solution:
To show an UI in the method above from my menu I would have to refer all assemblies (Business, PModel, UI) from my Menu class. Considering I have split the modules into a number of physical assemblies, that would be a dificult task to add references to about 60 different assemblies. Also the approach is not very scalable since I would certainly need to release more modules and with this approach I would have to change the source code every time I release a new module.
So primarily to avoid the reference of so many assemblies from my Menu class (assembly) I did as below -
Stored all the dependency described above in a database table (SQL Server), e.g.
ModuleShortCode | BModelAssembly | BModelFullTypeName | PModelAssembly | PModelFullTypeName | UIAssembly | UIFullTypeName
Now used a static class named "Launcher" with a method "Launch" as below -
Launcher.Launch("Discount");
Launcher.Launch("Customers");
The Launcher internally uses data from the dependency table and uses Activator.CreateInstance() to create each of the objects and uses the instance as constructor parameter to the next object being created, till the UI is built. The UI is then shown as a modal dialog. The code inside Launcher is somewhat like -
Form frm = ResolveForm("Discount");
frm.ShowDialog();`
The ResolveForm does the trick of building the chain of objects.
Can Unity help me here?
Now when I did that I did not have enough information on Unity and now that I have studied Unity I think I have been doing more or less the same thing. So I tried to replace my code with Unity.
However, as soon as I started I hit a block. If I try to resolve UI forms in my Menu as
Form customers = myUnityContainer.Resolve<Customers>();
or
Form customers = myUnityContainer.Resolve(typeof(Customers));
Then either way, I need to refer to my UI assembly from my Menu assembly since the target Type "Customers" need to be known for Unity to resolve it. So I am back to same place since I would have to refer all UI assemblies from the Menu assembly. I understand that with Unity I would have to refer fewer assemblies (only UI assemblies) but those references are needed which defeats my objectives below -
Create the chain of objects dynamically without any assembly reference from Menu assembly. This is to avoid Menu source code changing every time I release a new module. My Menu also is built dynamically from a table.
Be able to supply new modules just by supplying the new assemblies and inserting the new Dependency row in the table by a database patch.
At this stage, I have a feeling that I have to do it the way I was doing, i.e. Activator.CreateInstance() to fulfil all my objectives. I need to verify whether the community thinks the same way as me or have a better suggestion to solve the problem.
The post is really long and I sincerely thank you if you come til this point. Waiting for your valuable suggestions.
Rajarshi
As I can see from this code
Form customers = myUnityContainer.Resolve<Customers>();
all your code need to know about the customer - is that it's a Form class. So if you use xml configuration for unity you can do the following:
<type type="Form" mapTo="Customer" name="Customer">
</type>
And then you'll be able to resolve it like this:
Form customers = myUnityContainer.Resolve<Form>("Customer");
and there is no need to refference your UI assembly. Offcourse it should be presented in the bin directory or GAC. In this case if you'll develop new Assembly - all you need is to change config and put in in bin or gac.
If you want to make unity configuration from db then you'll have to add referrence to your ui, becouse you'll have to call Register("Customer").

ASP.NET options/command generator framework?

I want to put context-sensitive, dynamic command options on my asp.net pages.
I tried coding my own command structure but it's not very good, and I'm sure there must be a framework for doing this somewhere I can re-use?
Example:
I have a detailsview for some database object, I want to code in the object class what commands are available, based on the state of the object. I then want a UI object I can place on the webform that will pass commands back to the object when user clicks them, or jump to a different link (e.g. when additional parameters are available).
e.g. form might look like this
Product Details
Name: XXXX product
Price: $1.00
Qty: 1
Commands:
> Edit
> New Stock
> Mark as obsolete
So the commands at the bottom would have very little UI code and pass actions back to the object. For example the New Stock command would jump to a new page to ask for a quantity.
I don't know of the framework, but you could create something yourself. Let's say you are using MVP pattern, and assuming that this is a CRUD application, you could tell each view what type of object it is related to, then annotate you object with operations that are available. Then Presenter could call Service to perform the operation. You could name your methods using some convention so that you can wire it up in a Service. It is a lot of work, and unless you have 100s of views it is not worth while. I am building app that is about that size, and I am in process of creating GenericMVP framework, that would make wiring a breeze.

Resources