Post data from one page to another page

Naresh Ede asked on October 6, 2017 06:57

Hi

I want to post data from source page to destination page like

<form id="form1" runat="server" method="post" action="/destination">
    <asp:Button runat="server" ID="btnPOSt" Text="POST" OnClick="btnPOSt_Click"  />
</form>

So i was trying to add a form tag in page template then i got error "A page can have only one server-side Form tag."

so i assumed based on the error, this page already had a form tag, and i can access the form properties and added a code snippet like this

protected override void OnLoad(EventArgs e)
{
 this.Form.Action= "/destination";
}  

Now according to my assumption when clicking on button ,the page is navigated to "/destination" page. But it is showing error http://server/CMSVirtualFiles/Templates/Shared/=vg=46b85da9-e439-415a-8d90-77a34b91f265/Input.ascx(13): error CS1061: 'ASP.cmsvirtualfiles_templates_shared__vg_46b85da9_e439_415a_8d90_77a34b91f265_input_ascx' does not contain a definition for 'Form' and no extension method 'Form' accepting a first argument of type 'ASP.cmsvirtualfiles_templates_shared__vg_46b85da9_e439_415a_8d90_77a34b91f265_input_ascx' could be found (are you missing a using directive or an assembly reference?).

can anybody help me ????

If my requirement is not possible in the above approach, please suggest me the proper approach.

I want to navigate from source page to destination page with some data, that data should not be included in query strings.

Thank You Naresh Ede

Recent Answers


Matt Nield answered on October 6, 2017 10:13

Hi Naresh,

Kentico is built on ASP.NET, and the Kentico site you are referencing is build usign either the portal engine or ASPX templates meaning it's using WebForms. The error is correct, you can only have a single form in ASP.NET WebForms application. You should not really attempt to modify the form action in this way. If your data is simple, have you though about using the query string rather than a form?

In terms of what you are trying ot post to another page, it ould be helpful if you could describe the user journey that you want to create so that alternate solutions can be proposed. There are a number of waays of capturing a moving data about in Kentico and the specific scenario will help you shose which one to use.

0 votesVote for this answer Mark as a Correct answer

Naresh Ede answered on October 6, 2017 10:44

Thanks Matt Nield

I don't want to use querystring because i'm carrying the user data to the page of current site domain alias to log the user in all domains.

Hope you understand my scenario and please guide me.

0 votesVote for this answer Mark as a Correct answer

Suneel Jhangiani answered on October 6, 2017 13:01

It seems like you are looking to do single sign-on.

0 votesVote for this answer Mark as a Correct answer

Naresh Ede answered on October 6, 2017 14:11 (last edited on October 6, 2017 14:12)

Hi Suneel Jhangiani

I had seen that, but the API method GetUserAuthenticationUrl add user guid as querystring parameter string url = AuthenticationHelper.GetUserAuthenticationUrl(userInfo, "/default.aspx");

Like this "http://demo.com/autologin?authenticationguid=c98549d7-dbec-4367-b764-e4941ded0be8"

I think this is not safe to pass sensible information in query parameters.

0 votesVote for this answer Mark as a Correct answer

Suneel Jhangiani answered on October 6, 2017 14:39

The AuthenticationGuid that is being passed in the querystring is a temporary value created by the GetUserAuthenticationUrl method and is stored in the User.UserAuthenticationGUID field. This field should get cleared once the user is authenticated on redirection and hence should not pose any risk to sensitive information and a minimal risk to an attacker compromising the system due to the low lifetime of the temporary value.

0 votesVote for this answer Mark as a Correct answer

Matt Nield answered on October 6, 2017 15:18

Hi, inline with Suneel: the authentication GUID gets reset once used, thus reducing the risk o it being used maliciously. So you should beable to use that just fine.

0 votesVote for this answer Mark as a Correct answer

Naresh Ede answered on October 7, 2017 14:37

Thankyou for giving clarity on this, and one small doubt i have that where this temporary GUID stored and how it is going to expire.

        Guid gid = new Guid("c98549d7-dbec-4367-b764-e4941ded0be8");
        UserInfo us = UserInfoProvider.GetUserInfoByGUID(gid);

so if i use that generated guid to get userinfo in autologin page or any other method to expire the guid.

I think this is the last query i have.

ThankYou

0 votesVote for this answer Mark as a Correct answer

Matt Nield answered on October 9, 2017 12:08

Hi Naresh,

You should not need to generate the GUID yourself. Kentico will do this for you using the AuthenticationHelper. You can read more about Configuring single sign-on in the Kentico docs.

The key art you're looking for is : string userName = "testuser";

// Gets the user with the specified user name
UserInfo userInfo = UserInfoProvider.GetUserInfo(userName);

// Gets the authentication URL for a specified user and target URL
string url = AuthenticationHelper.GetUserAuthenticationUrl(userInfo, "/default.aspx");

From memory, once it has been used to login, the GUID is automatically replaced with a new one, so that link will no longer work.

0 votesVote for this answer Mark as a Correct answer

Suneel Jhangiani answered on October 16, 2017 17:21

Sorry for not replying to this thread sooner, I missed the email notification.

The temporary ID is stored in the UserAuthenticationGUID field of the CMS_User table and can be accessed via the UserAuthenticationGUID property of the User object using the API.

I also believe that once it is entered it remains there until the user authenticates using it in at which time it is removed and the field will either be null or an empty guid.

This should satisfy your requirement, since it would be generated in code and then the user is immediately transferred to a page which will authenticate it and remove it, so the entry should only exist for a small fraction of time.

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.