Reading classic asp files and finding variables - c#

I'm creating a console application to read classic asp page files and find certain functions. A lot of the functions I can use regex to get what I want which I then use the the text retrieved to query a database. An example of what I can already do -
This is a classic asp function (GetContentDirect) and I want to get the parameters which is easy to do with the below code. I would need to get the text CONTENT Logout and query the database with those words.
xsl.addText "Logout", obj_Content.GetContentDirect("CONTENT Logout")
The problem however is that the parameters for the functions are also variables or text and variables. Like the below code -
obj_node.appendChild obj_xml.createCDATASection(obj_Content.getContentDirect("CONTENT " & str_Temp))
I would need to get the value of str_Temp which is assigned elsewhere on the page. Whats the best way to go about doing this?

If your "variables" are actually constants, the solution is rather straightforward. Just let your console application know about the constants.
But, if they are truly variables, it seems the easiest way to get the values for all code paths would be to actually execute the code.
Modify your functions to log each time it is called, including the value of each parameter. Then crawl your site and run your console app against the resulting logs.

Related

.net Replace text with username at runtime

I am writing a C# .net website for management use within my company. On this page, I have a location on the main page to hold notices, which are contextually colored information panels. On the options page, you are given the ability to create them by filling out a form containing the notification's title, message, and a drop down for its class.
One of the the options I would like to provide for the users is to use {name} within the message to show the username of the person viewing the notification. I attempted to use message.Replace("{name}", "<asp:LoginName ID=\"LoginName1\" runat=\"server\" />");, but this resulted in that exact string being posted as opposed to the .net parser converting it into the username.
I am using the default asp.net user creation engine and database, though I've also heard that Silverlight is now the standard.
As for my questions, would I be better off rebuilding the project in Silverlight, assuming Silverlight has the capability to handle secure logins? Also, what would be the correct way to go about replacing the username? Would I be better off with something like {user=#} where # is the user's ID? Theoretically, it would just be a database query from within my Notice class (the constructor calling a method that replaces bbcode with its html counterpart).
Thank you for your help
<asp:LoginName ID=\"LoginName1\" runat=\"server\" /> will work only if directly put in the ASPX. If you want to dynamically set the name without using a control, there's two way:
From the page's code-behind, you can call this.User.Identity.Name
From anywhere in the app, you can call HttpContext.Current.User.Identity.Name

How can I copy HTML textbox values from one domain to another domain's textboxes?

I'm trying to help save time at work with for a lot of tedious copy/paste tasks we have.
So, we have a propitiatory CRM (with proper HTML ID's, etc for accessing elements) and I'd like to copy those vales from the CRM to textboxes on other web pages (outside of the CRM, so sites like Twitter, Facebook, Google, etc)
I'm aware browsers limit this for security and I'm open to anything, it can be a C#/C++ application, Adobe AIR, etc. We only use Firefox at work so even an extension would work. (We do have GreaseMonkey installed so if that's usable too, sweet).
So, any ideas on how to copy values from one web page to another? Ideally, I'm looking to click a button and have it auto-populate fields. If that button has to launch the web pages that need to be copied over to, that's fine.
Example: Copy customers Username from our CRM, paste it in Facebook's Username field when creating a new account.
UPDATE: To answer a user below, the HTML elements on each domain have specific HTML ID's. The data won't need to be manipulated or cleaned up, just a simple copy from ourCRM.com to facebook.com / twitter.com
Ruby Mechanize is a good bet for scraping the data. Then you can store it and post it however you please.
First, I'd suggest that you more clearly define exactly what it is you're looking to do. I read this as you're trying to take some unstructured data from Point A and copy it to Point B. Do the names of these fields remain constant every time you do the operation? Do you need to simply pull any textbox elements from the page and copy them all over? Do some sort of filtering of this data before writing it over?
Once you've got a clear idea of the requirements, if you go the C# route, I'd use something like SimpleBrowser. Judging by the example on their Github page, you could give it the URL of the page you're looking to copy, then name each of the fields you're looking to obtain the value of, perhaps store these in an IDictionary, then open a new URL and copy those values back into the page (and submit the form).
Alternatively, if you don't know the names of the fields, perhaps there's a provided function in that or a similar project that will allow you to simply enumerate all the text fields on the page and retrieve the values for all of them. Then you'd simply apply some logic of your own to filter those options down to whatever is on the destination form.
SO we thought of an easier way to do this (in case anyone else runs into this issue).
1) From our CRM, we added a "Sign up for Facebook" button
2) The button opens a new window with GET variables in the URL
3) Use a greasemonkey script to read those GET variables and fill in textbox values
4) SUCCESS!
Simple, took about 10 minutes to get working. Thanks for you suggestions.

how to get variable in desktop c# program from web javascript application

I met a problem that there are two applications. one is desktop application in c#, and another is web application in javascript. some variables or informations in running desktop application are needed to transfer to web application.
Does any one know how to solve this?
Does any one would like to provide more details to solve this?
Regards,
I think the processes are very well separated and unless you use a sole handler for c# + js (c#.net to render your page for instance) it is going to be impossible to retrieve data.
Maybe you can get something from the webbrowser object: running it on your page you might gain access to some of your web variables...
Also, if the c# app writes data in a file, the js could read it...
Have fun
Rgds
When you open the web application, pass the variables in as query string parameters and you can get them using javascript various ways, some of which are noted here

How to make a Dictionary and Utility in C#?

I have 15 web pages that has the same labels. But, in one case, I need to change all of their Text, in all pages. Other than writing them all by one, I want to make something general and public that I can use in all the pages. The ID's of the labels are same. I don't know how to do it with different web pages. Can you give me a hint? I don't know if its called Utility or Dictionary. A friend of mine mentioned it a few mins ago but I don't want to ask her again she already thinks I am dumb :(
They are ASP.NET pages with C# also I am using Devexpress.
I want to change only one web page at a time. But use the method for all web pages when they are shown (by the user). Not changing all the 15 at the same time.
If the informations shown on the labels are the same for every user, you could use the ASP.NET Cache.
How to: Add Items to the Cache
How to: Retrieve Values of Cached Items
If not, you could use the Session.
But normally you would use a dbms for this purpose, for example SQL-Server.
Note: Do not use the Label's ID as Keys for the Cache/Session/Database but the meaning. ID's may change, apart from that it's much more readable.

C# application to read in and translate other applications

I am trying to build a Translation Assistant which can read in other compiled C# application (.exe), and display the forms from the EXE, are displayed individually, along with a table next to it with english column which will show the current english words on display, and another column for the value, which a translator can enter. Once completed translations, the translator can export the translations a resx file, to add to a project and also as an excel file for record purposes.
I am new to C# and hence am not sure if my strucute is correct, i have designed in such that a dll is inserted into the .exe during compilator, and then using this dll, the translation application can extract the string. This works for most strings, but it is getting stuck where there are several string that can apear in the same textbox at different times [e.g. disconnected, connected etc]. I have tried searching everywhere, but I am not able to find information on how i will be able to pull out all strings from an application, and be able to identify which form they belong to, in order to create my application?
the other issue i am faced with is, actually displaying the translated strings, the application i am building would benifit greatly if it could display a example of how the translated strings would look, as translations in some languages could be excessivly long. but i have found that i am only able to read in the aspects of the compiled applications and create an instance, but am not able to translate it.
I am reading in the exe using Reflection, and have understood from online that i need to use reflection.emit to modify the form. but i am finding every sting that is idenfitied from the form, is extracted as an instance, hence changing the string is only changing the instance of the strings , and not the instance of the form itself. hence i am not able so a correct display.
I have been trying for 3 weeks to solve these last two questions, Thanks in advance for helping me solve this.
I think you can't find a general solution to your problem with the texts that may appear in the textbox. Here is why:
If the texts are in the resource file, you could read them, but you still don't know where they are used. You would need to do a complex analysis of the source code to know, where the text is displayed. Just imagine this little scenario:
textBox.Text = GetCorrectText(connection.State);
GetCorrectText could look like this:
string GetCorrectText(ConnectionState state)
{
return string.Format(Resources.ConnectionState, state);
}
Resources.ConnectionState might be "The connection is in the state {0}".
Its a simple example, but you would need to know or extract a lot of things:
The text property of the TextBox class is the string that is shown to the user
The Method GetCorrectText returns the text, so you need to parse it.
The Method string.Format returns the text. Now you either would need to hardcode that for string.Format it should use the first parameter as the text that is displayed or you would have to parse string.Format to learn that fact.
The example shows something else: You wouldn't be able to translate the whole string that is being displayed, because part of it is the name of the enum value.
What I want to show you is that you need to make trade offs.

Categories

Resources