Products

Solutions

Resources

Partners

Community

About

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesProper way to use ServicesFramework.Instance.RequestAjaxAntiForgerySupport in NON-MVC Razor Script?Proper way to use ServicesFramework.Instance.RequestAjaxAntiForgerySupport in NON-MVC Razor Script?
Previous
 
Next
New Post
3/26/2018 5:46 AM
 
Having played around the WebAPI and Razor script for a while but still not too sure how to get the AntiForgerySupport works...

The Dnn.ServicesFramework.js never loads unless I've login to the site. Am I missing anything in the _view.cshtml? The _view.cshtml is created by DNN Module Creator. (I'm testing it now using the latest DNN version 9.2.0)

Also just wondering if it is possible to get the global dnn variables (e.g. TabID and ModuleID) works on an external JS file instead of having the script in the _view.cshtml (the js file is inject via DNN ClientResourceManager)? or I have to pass every single value manually to the script?
 
New Post
4/18/2018 1:49 PM
 

To enable AntiForgerySupport you need to add these to your c# backend. I add them to the OnInit method:

protected override void OnInit(EventArgs e)
{
        ServicesFramework.Instance.RequestAjaxScriptSupport();
        ServicesFramework.Instance.RequestAjaxAntiForgerySupport();
}

I then access it like so:

var sf = $.ServicesFramework(moduleId);
sf.getAntiForgeryValue();

I've been using the SPA template and have not found a solution for adding AntiForgerySupport into a SPA module without having an assembly attached. I fixed this by adding the above to my skins template which should provide this support on any page using that skin.

BTW you can use the token system to inject the module Id into your template like so (ModuleId & IsSuperUser are the only two supported):

<div id="root" data-module-id="[ModuleContext:ModuleId]" data-is-superuser="[ModuleContext:IsSuperUser]">
  <!-- content -->
</div>
 
New Post
4/19/2018 12:58 AM
 
Hi Michael,
Thank you for your reply.

Unfortunately there is no back end C# code when creating my razor module from the DNN Module Creator so I cannot add the back end code :( Currently my solution is to create another WebForm module from the module creator to add the sf back end code.

I have also sort out the javascript part to get the sf works.

Can you tell me more about your way to embed the OnInit method to your skin? Do you create another ascx control to get it work?
 
New Post
4/19/2018 4:03 AM
 
I figured out how to add the backend code into the skin by a bit trial and error :)
Was trying to create a C# inline-script module from the DNN Module Creator and find the bits and pieces from the code. Tried to paste the following and it works!

<%@ Import Namespace="System" %>
<%@ Import Namespace="DotNetNuke.Entities.Modules" %>
<%@ Import Namespace="DotNetNuke.Framework" %>
<script runat="server">
	#region Event Handlers

	protected override void OnInit(EventArgs e)
	{
		base.OnInit(e);
	}

	protected override void  (EventArgs e)
	{
		base. (e);
                ServicesFramework.Instance.RequestAjaxAntiForgerySupport();
	}
		
	#endregion
</script>
 
New Post
4/19/2018 4:09 AM
 
weird the method On Load (one word) become white spacing when pasting the code...anyway add it after void and base.
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesProper way to use ServicesFramework.Instance.RequestAjaxAntiForgerySupport in NON-MVC Razor Script?Proper way to use ServicesFramework.Instance.RequestAjaxAntiForgerySupport in NON-MVC Razor Script?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out