|
WebPageControllerPostPage Method
|
Common page post handler.
Namespace: GSF.Web.HostingAssembly: GSF.Web (in GSF.Web.dll) Version: 2.4.246-beta
Syntax[ValidateRequestVerificationTokenAttribute(FormValidation = true)]
[ActionNameAttribute("GetPage")]
[HttpPostAttribute]
public Task<HttpResponseMessage> PostPage(
string pageName,
CancellationToken cancellationToken
)
<ValidateRequestVerificationTokenAttribute(FormValidation := true)>
<ActionNameAttribute("GetPage")>
<HttpPostAttribute>
Public Function PostPage (
pageName As String,
cancellationToken As CancellationToken
) As Task(Of HttpResponseMessage)
public:
[ValidateRequestVerificationTokenAttribute(FormValidation = true)]
[ActionNameAttribute(L"GetPage")]
[HttpPostAttribute]
Task<HttpResponseMessage^>^ PostPage(
String^ pageName,
CancellationToken cancellationToken
)
[<ValidateRequestVerificationTokenAttribute(FormValidation = true)>]
[<ActionNameAttribute("GetPage")>]
[<HttpPostAttribute>]
member PostPage :
pageName : string *
cancellationToken : CancellationToken -> Task<HttpResponseMessage>
function PostPage(pageName, cancellationToken);
View SourceParameters
- pageName String
- Page name to render.
- cancellationToken CancellationToken
- Propagates notification from client that operations should be canceled.
Return Value
TaskHttpResponseMessageRendered page result for given page.
Remarks
For Ajax post-based requests to pages handled by this controller, the Ajax request will need to specify
verification token in the header and set flag that indicates an Ajax request. See example code below:
@{
string verificationHeader = AuthenticationOptions.DefaultRequestVerificationToken;
string useAjaxVerfication = AuthenticationOptions.DefaultAjaxRequestVerificationToken;
ReadonlyAuthenticationOptions options = ViewBag.AuthenticationOptions;
if (options != null) {
if (!string.IsNullOrWhiteSpace(options.RequestVerificationToken)) {
verificationHeader = options.RequestVerificationToken;
}
if (!string.IsNullOrWhiteSpace(options.AjaxRequestVerificationToken)) {
useAjaxVerfication = options.AjaxRequestVerificationToken;
}
}
string verificationValue = Html.RequestVerificationHeaderToken();
string constants = string.Format(@"
const verificationHeader = ""{0}"";
const verificationValue = ""{1}"";
const useAjaxVerfication = ""{2}"";
",
verificationHeader.JavaScriptEncode(),
verificationValue.JavaScriptEncode(),
useAjaxVerfication.JavaScriptEncode()
);
}
@section Scripts {
<script>
"use strict";
@Raw(new Minifier().MinifyJavaScript(constants));
function doAjaxThing() {
$.ajax({
cache: false,
url: "AjaxThing.ashx",
method: "post",
data: { value: "some data to post" },
dataType: "application/json",
success: function (result) {
console.log("Success: " + result);
},
beforeSend: function (xhr) {
xhr.setRequestHeader(verificationHeader, verificationValue);
xhr.setRequestHeader(useAjaxVerfication, "true");
}
});
}
</script>
}
See Also