> For the complete documentation index, see [llms.txt](https://docs.starcounter.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.starcounter.io/2.3.1/cookbook/attach-a-request-to-long-running-transactions.md).

# Attach an HTTP Request to an Existing Long-Running Transaction

When you are building a multi-page application, it might be useful to create an object in a transaction without committing it.

If you want to provide the user with a URL to an uncommitted object, you will need to attach the view-model of the request handler to the existing long-running transaction.

The following button handler creates a `Person` object and redirects to its page, without committing the object:

```csharp
public void Handle(Input.CreatePerson action)
{
    var person = new Person()
    {
        FirstName = "Uncommitted Guy"
    };

    RedirectUrl = "/people/persons/" + person.GetObjectID();
}
```

When the request handler for `"/people/persons/{?}"` catches the request after the redirection, it needs to search for the object by its ID in the existing long-running transaction:

```csharp
Handle.GET("/people/persons/{?}", (string id) =>
{
    MasterPage master = GetMasterPageFromSession();

    Action runPartialInScope = () =>
    {
        master.CurrentPage = Self.GET("/people/partials/persons/" + id);
    };

    if (master.CurrentPage.Transaction != null)
    {
        // Attach to a long running transaction of the existing CurrentPage
        master.CurrentPage.Transaction.Scope(runPartialInScope);
    }
    else
    {
        // If there was no existing CurrentPage, create a new transaction
        Db.Scope(runPartialInScope);
    }

    return master;
});
```

### Read more

[Guide: Long-running transactions](/2.3.1/guides/transactions/long-running-transactions.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.starcounter.io/2.3.1/cookbook/attach-a-request-to-long-running-transactions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
