Skip to content

Conversation

@terrorbyte
Copy link
Collaborator

Adds a set off helper functions to help chain ASP.NET application state management functions. Historically, ASP.NET apps have been a bit of a nuisance to work with because of the way that each page gets set with a __VIEWSTATE and friends that had to be parsed and set and cased manually. In order to speed up this process this adds a set of functions to be able to parse and update state.

The following parameters are extracted when Update is called with a HTML document body:

  • __VIEWSTATE
  • __VIEWSTATEGENERATOR
  • __EVENTVALIDATION
  • __EVENTARGUMENT
  • __EVENTTARGET
  • __LASTFOCUS

For example from our tests in these additions:

state := aspnet.State{}
p := state.AsParams()
if len(p) != 0 {
	t.Error("Parameters should not have state currently")
}

state.Update(pageState1)
p = state.AsParams()
value, exists := p["__VIEWSTATE"]
if !exists {
	t.Error("ViewState should be set on first request state update")
}
if value != `/wEPDwULLTE4OTcxMDA5NzIPZBYCZg9kFgQCAw8WAh4EVGV4dGVkAgUPZBYIAgYPZBYCAjsPEGQPFgRmAgECAgIDFgQQBRREZWZhdWx0IC0gYWxsIGluIG9uZQUHZGVmYXVsdGcQBQZNeSBTcWwFBW15c3FsZxAFClNRTCBTZXJ2ZXIFA3NxbGcQBQpQb3N0Z3JlU1FMBQRwc3FsZxYBZmQCCA8PFgIeC05hdmlnYXRlVXJsBSVodHRwOi8vd3d3LmdsYWRpbmV0LmNvbS9wL2NvbnRhY3QuaHRtZGQCCQ8PFgIfAQUjaHR0cDovL3d3dy5nbGFkaW5ldC5jb20vcC90ZXJtcy5odG1kZAIKDw8WAh8BBSVodHRwOi8vd3d3LmdsYWRpbmV0LmNvbS9wL3ByaXZhY3kuaHRtZGRkhIVOv1laSf4FVfKCihTCvPyajtM=` {
	t.Error("ViewState on first update is unexpected")
}

value, exists = p["__LASTFOCUS"]
if !exists {
	t.Error("LastFocus should not be nil")
}
if value != `` {
	t.Error("LastFocus should be set but is an empty string")
}
if state.ViewStateGenerator == nil {
	t.Errorf("ViewStateGenerator should not be nil on first request: %#v", state.ViewStateGenerator)
}

state.Update(pageState2)
p = state.AsParams()
if len(p) == 0 {
	t.Error("Parameters should have state currently at state 2")
}
if len(p) != 4 {
	t.Errorf("Second state should only have 4 values: %d - %#v", len(p), p)
}
if state.ViewStateGenerator != nil {
	t.Errorf("ViewStateGenerator should be nil on second request: %#v", state.ViewStateGenerator)
}
if state.ViewState == nil {
	t.Errorf("ViewState should be not be nil on second request: %#v", state.ViewStateGenerator)
}
if *state.ViewState != `/wEPDwULLTE4OTcxMDA5NzIPZBYCZg9kFgQCAw8WAh4EVGV4dGVkAgUPZBYIAgYPZBYGAjsPEGQPFgRmAgECAgIDFgQQBRREZWZhdWx0IC0gYWxsIGluIG9uZQUHZGVmYXVsdGcQBQZNeSBTcWwFBW15c3FsZxAFClNRTCBTZXJ2ZXIFA3NxbGcQBQpQb3N0Z3JlU1FMBQRwc3FsZxYBAgNkAj0PDxYCHgdWaXNpYmxlaGRkAkUPDxYCHwFnZGQCCA8PFgIeC05hdmlnYXRlVXJsBSVodHRwOi8vd3d3LmdsYWRpbmV0LmNvbS9wL2NvbnRhY3QuaHRtZGQCCQ8PFgIfAgUjaHR0cDovL3d3dy5nbGFkaW5ldC5jb20vcC90ZXJtcy5odG1kZAIKDw8WAh8CBSVodHRwOi8vd3d3LmdsYWRpbmV0LmNvbS9wL3ByaXZhY3kuaHRtZGQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgEFIGN0bDAwJE1haW5Db250ZW50JFBTUUxDaGtTU0xNb2Rlt1OAugQHTFQSO9InFhq1a4zTB6w=` {
	t.Error("ViewState on second update is unexpected")
}

@terrorbyte terrorbyte self-assigned this Nov 21, 2025
@terrorbyte terrorbyte added the enhancement New feature or request label Nov 21, 2025
@j-baines j-baines requested a review from Copilot November 24, 2025 13:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces ASP.NET state management helpers to simplify interaction with ASP.NET applications that use hidden form fields for state preservation. The helpers parse and track common ASP.NET state parameters (__VIEWSTATE, __VIEWSTATEGENERATOR, __EVENTVALIDATION, __EVENTARGUMENT, __EVENTTARGET, __LASTFOCUS) across request chains, eliminating manual parsing and reducing boilerplate code.

Key changes:

  • New aspnet.State struct to track ASP.NET hidden form field values across requests
  • Helper methods to convert state to parameters, merge with custom parameters, and update from HTML responses
  • Comprehensive test coverage validating state parsing and updates across multiple page states

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
aspnet/aspnet.go Core implementation with State struct and helper methods (AsParams, MergeParams, Update)
aspnet/aspnet_test.go Test suite validating state parsing, parameter conversion, and merging functionality

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

j-baines and others added 2 commits November 24, 2025 08:08
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

@j-baines j-baines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think event.EventArgument vs. event.EventTarget needs to be looked at (and an associated test written if that is bugged). Otherwise, this seems good (and I'd just ignore the old man complaining about dependencies).

@terrorbyte terrorbyte requested a review from j-baines November 25, 2025 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants