Scenario: I have an internal ASP.NET site that allows me to maintain a set of rules (CRUD). To add a new rule I simply fill out a HTML form and click submit. My current issue is that I now need to add a few hundred rules and I want to use a script to automate this.
Initial plan:
- Create a script that can take X number of arguments and use these to fake a form submittal of the above web page
- Create a comma-separated file (or similar) with one row per rule and each column represents one of the input tags in the HTML form
- Create another script that can use the comma-separated file to execute the form-submittal script once for every row
My attempts has centered around curl, and worked well against an online testing page. Unfortunately I'm not able to get it to work against the ASP.NET page and I'm guessing this has to do something with Postback and/or Viewstate.
Snippet:
curl -s -u "DOMAIN\user:password" --ntlm -d "key1=value1" -d "key2=value2" http://internal/page.aspx
(Returns the page as if using a GET, no error messages)
Question:
How can I trick the ASP page that I'm sending a Postback? (alternative scripting suggestions are welcome as well)
EDIT:
Snippet from ASP page:
<asp:LinkButton ... runat="server" OnClick="lbAddRule_Click" PostBackUrl="~/Page.aspx" />
Snippet from code behind:
protected void lbAddRule_Click(object sender, EventArgs e) {
if (Page.IsValid == true) {
AddRule(x,y,z);
ViewStateinput field(or fields) from the page and submit those along with your request. That might be enough to make the page think it's a postback. Also, if this is pretty straight up CRUD, would it be easier to just insert stuff directly into whatever database backs this application?