<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="/rss.xsl"?><rss version="2.0"><channel><title>Orchard Project</title><link>http://orchard.codeplex.com/project/feeds/rss</link><description>Orchard is a free, open source, community-driven project aimed at delivering applications and reusable components on the ASP.NET platform.</description><item><title>New Post: Anti forgery exceptions when making ajax posts using JSON</title><link>http://orchard.codeplex.com/discussions/444623</link><description>&lt;div style="line-height: normal;"&gt;I recently ran into this problem and spent a good chunk of a day running through different threads and struggled to find a solution that I liked. Most of them wanted me to move away from JSON posts, but I feel like I should be able to do a JSON post if I want to. I'm not certain this is the best/correct solution, but it seems to work.&lt;br /&gt;
&lt;br /&gt;
Eventually I ran into: &lt;br /&gt;
&lt;a href="http://haacked.com/archive/2011/10/10/preventing-csrf-with-ajax.aspx" rel="nofollow"&gt;http://haacked.com/archive/2011/10/10/preventing-csrf-with-ajax.aspx&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
But when I attempted to duplicate it I found that the MVC code had changed since this was created which lead me to pulling down the MVC 4 source (&lt;a href="https://aspnetwebstack.codeplex.com/" rel="nofollow"&gt;https://aspnetwebstack.codeplex.com/&lt;/a&gt;).&lt;br /&gt;
&lt;br /&gt;
This all led me to editing the existing ValidateAntiForgeryTokenOrchardAttribute located in the orchard.framework project:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;    [AttributeUsage(AttributeTargets.Method)]
    public class ValidateAntiForgeryTokenOrchardAttribute :
    FilterAttribute, IAuthorizationFilter
    {
        private string _salt;

        public ValidateAntiForgeryTokenOrchardAttribute()
            : this(System.Web.Helpers.AntiForgery.Validate)
        {
        }

        internal ValidateAntiForgeryTokenOrchardAttribute(Action validateAction)
        {
            Debug.Assert(validateAction != null);
            ValidateAction = validateAction;
        }

        [SuppressMessage(&amp;quot;Microsoft.Naming&amp;quot;, &amp;quot;CA2204:Literals should be spelled correctly&amp;quot;, MessageId = &amp;quot;AdditionalDataProvider&amp;quot;, Justification = &amp;quot;API name.&amp;quot;)]
        [SuppressMessage(&amp;quot;Microsoft.Naming&amp;quot;, &amp;quot;CA2204:Literals should be spelled correctly&amp;quot;, MessageId = &amp;quot;AntiForgeryConfig&amp;quot;, Justification = &amp;quot;API name.&amp;quot;)]
        [Obsolete(&amp;quot;The 'Salt' property is deprecated. To specify custom data to be embedded within the token, use the static AntiForgeryConfig.AdditionalDataProvider property.&amp;quot;, error: true)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public string Salt
        {
            get { return _salt; }
            set
            {
                if (!String.IsNullOrEmpty(value))
                {
                    throw new NotSupportedException(&amp;quot;The 'Salt' property is deprecated. To specify custom data to be embedded within the token, use the static AntiForgeryConfig.AdditionalDataProvider property.&amp;quot;);
                }
                _salt = value;
            }
        }

        internal Action ValidateAction { get; private set; }

        public void OnAuthorization(AuthorizationContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException(&amp;quot;filterContext&amp;quot;);
            }

            var request = filterContext.HttpContext.Request;
            if (!string.IsNullOrEmpty(request.Headers[&amp;quot;__RequestVerificationToken&amp;quot;]))
            {
                //We use the token in the header to support json requests.
                var cookieToken = request.Cookies[&amp;quot;__RequestVerificationToken&amp;quot;] == null
                    ? &amp;quot;&amp;quot; : request.Cookies[&amp;quot;__RequestVerificationToken&amp;quot;].Value;
                var formToken = request.Headers[&amp;quot;__RequestVerificationToken&amp;quot;];
                System.Web.Helpers.AntiForgery.Validate(cookieToken, formToken);
            }
            else
            {
                ValidateAction();
            }
        }
    }
}&lt;/code&gt;&lt;/pre&gt;

Which is basically the asp.net 4 ValidateAntiForgeryTokenAttribute with this chunk added to it:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;    if (!string.IsNullOrEmpty(request.Headers[&amp;quot;__RequestVerificationToken&amp;quot;]))
    {
        //We use the token in the header to support json requests.
        var cookieToken = request.Cookies[&amp;quot;__RequestVerificationToken&amp;quot;] == null
            ? &amp;quot;&amp;quot; : request.Cookies[&amp;quot;__RequestVerificationToken&amp;quot;].Value;
        var formToken = request.Headers[&amp;quot;__RequestVerificationToken&amp;quot;];
        System.Web.Helpers.AntiForgery.Validate(cookieToken, formToken);
    }&lt;/code&gt;&lt;/pre&gt;

This basically changes the AntiForgery validation to also check the headers of the request for the request verification token. Next I changed the AntiForgeryAuthorizationFilter (also located in the orchard.framework folder) to use the updated ValidateAntiForgeryTokenOrchardAttribute instead of the old ValidateAntiForgeryTokenAttribute:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;var validator = new ValidateAntiForgeryTokenOrchardAttribute();&lt;/code&gt;&lt;/pre&gt;

At this point you should then be able to make Ajax posts using JSON something like this:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;               var headers = {};
        headers['__RequestVerificationToken'] = '@(Html.AntiForgeryTokenValueOrchard())';
        $.ajax
        ({
            type: &amp;quot;Post&amp;quot;,
            url: url,
            async: true,
            dataType: &amp;quot;json&amp;quot;,
            headers: headers,
                contentType: 'application/json; charset=utf-8',
            data: JSON.stringify(postData), 
            success: function (response) {
            }
        });&lt;/code&gt;&lt;/pre&gt;

If anyone happens to know this is terribly wrong for some reason please let me know! Hopefully it helps save someone else a little time.&lt;br /&gt;
&lt;br /&gt;
PS: Inside the AntiForgeryAuthorizationFilter there's some similar sort of action put into play by Orchard going on around:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;//HAACK: (erikpo) If the token is in the querystring, put it in the form so MVC can validate it&lt;/code&gt;&lt;/pre&gt;

I was unable to fix my issue by duplicating that sort of logic so I'm not actually sure that this still works, it might make more sense to handle it similar to how this was done.&lt;br /&gt;
&lt;/div&gt;</description><author>bonneyab</author><pubDate>Wed, 22 May 2013 17:04:56 GMT</pubDate><guid isPermaLink="false">New Post: Anti forgery exceptions when making ajax posts using JSON 20130522050456P</guid></item><item><title>New Post: Serving static content directly - bypassing the .NET pipeline</title><link>http://orchard.codeplex.com/discussions/431921</link><description>&lt;div style="line-height: normal;"&gt;First off - thank you for the response.  We are using Orchard 1.6 and if we switch this setting to false, can you tell us if the out of the box Orchard installation will have any problems?  Thanks again...&lt;br /&gt;
&lt;/div&gt;</description><author>jlebright</author><pubDate>Wed, 22 May 2013 16:51:15 GMT</pubDate><guid isPermaLink="false">New Post: Serving static content directly - bypassing the .NET pipeline 20130522045115P</guid></item><item><title>Edited Unassigned: Publish with web deploy fails since last orchard.web.csproj / hostcomponents.config modif  [19736]</title><link>http://orchard.codeplex.com/workitem/19736</link><description>Unable to find path &amp;#39;E&amp;#58;&amp;#92;Config&amp;#92;HostComponents.config&amp;#39;.&amp;#9;E&amp;#58;&amp;#92;xxxb&amp;#92;Orchard.Web.csproj&amp;#9;241&amp;#9;5&amp;#9;Orchard.Web&lt;br /&gt;&lt;br /&gt;</description><author>sebastienros</author><pubDate>Wed, 22 May 2013 16:49:41 GMT</pubDate><guid isPermaLink="false">Edited Unassigned: Publish with web deploy fails since last orchard.web.csproj / hostcomponents.config modif  [19736] 20130522044941P</guid></item><item><title>New Post: Why implicit transactions at Session creation?</title><link>http://orchard.codeplex.com/discussions/440765</link><description>&lt;div style="line-height: normal;"&gt;Again, Orchard is dependent on this feature, and Nhibernate requires it too.&lt;br /&gt;
&lt;br /&gt;
But feel free do fork Orchard and show us how little work it takes and how much performance gain you get. Might convince everyone.&lt;br /&gt;
&lt;/div&gt;</description><author>sebastienros</author><pubDate>Wed, 22 May 2013 16:47:32 GMT</pubDate><guid isPermaLink="false">New Post: Why implicit transactions at Session creation? 20130522044732P</guid></item><item><title>New Post: Why implicit transactions at Session creation?</title><link>http://orchard.codeplex.com/discussions/440765</link><description>&lt;div style="line-height: normal;"&gt;Again, Orchard is dependent on this feature, and Nhibernate requires it too.&lt;br /&gt;
&lt;br /&gt;
But feel free do fork Orchard and show us how little work it takes and how much performance gain you get. Might convince everyone.&lt;br /&gt;
&lt;/div&gt;</description><author>sebastienros</author><pubDate>Wed, 22 May 2013 16:47:32 GMT</pubDate><guid isPermaLink="false">New Post: Why implicit transactions at Session creation? 20130522044732P</guid></item><item><title>New Post: Why implicit transactions at Session creation?</title><link>http://orchard.codeplex.com/discussions/440765</link><description>&lt;div style="line-height: normal;"&gt;Again, Orchard is dependent on this feature, and Nhibernate requires it too.&lt;br /&gt;
&lt;br /&gt;
But feel free do fork Orchard and show us how little work it takes and how much performance gain you get. Might convince everyone.&lt;br /&gt;
&lt;/div&gt;</description><author>sebastienros</author><pubDate>Wed, 22 May 2013 16:47:32 GMT</pubDate><guid isPermaLink="false">New Post: Why implicit transactions at Session creation? 20130522044732P</guid></item><item><title>New Post: Why implicit transactions at Session creation?</title><link>http://orchard.codeplex.com/discussions/440765</link><description>&lt;div style="line-height: normal;"&gt;Again, Orchard is dependent on this feature, and Nhibernate requires it too.&lt;br /&gt;
&lt;br /&gt;
But feel free do fork Orchard and show us how little work it takes and how much performance gain you get. Might convince everyone.&lt;br /&gt;
&lt;/div&gt;</description><author>sebastienros</author><pubDate>Wed, 22 May 2013 16:47:32 GMT</pubDate><guid isPermaLink="false">New Post: Why implicit transactions at Session creation? 20130522044732P</guid></item><item><title>New Post: Why implicit transactions at Session creation?</title><link>http://orchard.codeplex.com/discussions/440765</link><description>&lt;div style="line-height: normal;"&gt;Again, Orchard is dependent on this feature, and Nhibernate requires it too.&lt;br /&gt;
&lt;br /&gt;
But feel free do fork Orchard and show us how little work it takes and how much performance gain you get. Might convince everyone.&lt;br /&gt;
&lt;/div&gt;</description><author>sebastienros</author><pubDate>Wed, 22 May 2013 16:47:32 GMT</pubDate><guid isPermaLink="false">New Post: Why implicit transactions at Session creation? 20130522044732P</guid></item><item><title>New Post: nhibernate session change tracking</title><link>http://orchard.codeplex.com/discussions/444472</link><description>&lt;div style="line-height: normal;"&gt;Sounds good. I guess I won't be able to get dirty entities until the session is flushed and some event is cought by the interceptor, because nhibernate entities are not self tracking.&lt;br /&gt;
&lt;br /&gt;
Thanks for the answer.&lt;br /&gt;
&lt;/div&gt;</description><author>kassobasi</author><pubDate>Wed, 22 May 2013 16:06:25 GMT</pubDate><guid isPermaLink="false">New Post: nhibernate session change tracking 20130522040625P</guid></item><item><title>New Post: nhibernate session change tracking</title><link>http://orchard.codeplex.com/discussions/444472</link><description>&lt;div style="line-height: normal;"&gt;Sounds good. I guess I won't be able to get dirty entities until the session is flushed and some event is cought by the interceptor, because nhibernate entities are not self tracking.&lt;br /&gt;
&lt;br /&gt;
Thanks for the answer.&lt;br /&gt;
&lt;/div&gt;</description><author>kassobasi</author><pubDate>Wed, 22 May 2013 16:06:25 GMT</pubDate><guid isPermaLink="false">New Post: nhibernate session change tracking 20130522040625P</guid></item><item><title>New Post: nhibernate session change tracking</title><link>http://orchard.codeplex.com/discussions/444472</link><description>&lt;div style="line-height: normal;"&gt;Sounds good. I guess I won't be able to get dirty entities until the session is flushed and some event is cought by the interceptor, because nhibernate entities are not self tracking.&lt;br /&gt;
&lt;br /&gt;
Thanks for the answer.&lt;br /&gt;
&lt;/div&gt;</description><author>kassobasi</author><pubDate>Wed, 22 May 2013 16:06:25 GMT</pubDate><guid isPermaLink="false">New Post: nhibernate session change tracking 20130522040625P</guid></item><item><title>New Post: Custom search in Orchard</title><link>http://orchard.codeplex.com/discussions/444410</link><description>&lt;div style="line-height: normal;"&gt;Thanks.&lt;br /&gt;
&lt;/div&gt;</description><author>leotran</author><pubDate>Wed, 22 May 2013 16:06:09 GMT</pubDate><guid isPermaLink="false">New Post: Custom search in Orchard 20130522040609P</guid></item><item><title>New Post: Custom search in Orchard</title><link>http://orchard.codeplex.com/discussions/444410</link><description>&lt;div style="line-height: normal;"&gt;Thanks.&lt;br /&gt;
&lt;/div&gt;</description><author>leotran</author><pubDate>Wed, 22 May 2013 16:06:09 GMT</pubDate><guid isPermaLink="false">New Post: Custom search in Orchard 20130522040609P</guid></item><item><title>New Post: Event for updating content type definition</title><link>http://orchard.codeplex.com/discussions/444264</link><description>&lt;div style="line-height: normal;"&gt;Thanks, I will take a look and try both solutions.&lt;br /&gt;
&lt;/div&gt;</description><author>pwasiewicz</author><pubDate>Wed, 22 May 2013 15:40:30 GMT</pubDate><guid isPermaLink="false">New Post: Event for updating content type definition 20130522034030P</guid></item><item><title>New Post: Event for updating content type definition</title><link>http://orchard.codeplex.com/discussions/444264</link><description>&lt;div style="line-height: normal;"&gt;Thanks, I will take a look and try both solutions.&lt;br /&gt;
&lt;/div&gt;</description><author>pwasiewicz</author><pubDate>Wed, 22 May 2013 15:40:30 GMT</pubDate><guid isPermaLink="false">New Post: Event for updating content type definition 20130522034030P</guid></item><item><title>New Post: Event for updating content type definition</title><link>http://orchard.codeplex.com/discussions/444264</link><description>&lt;div style="line-height: normal;"&gt;Thanks, I will take a look and try both solutions.&lt;br /&gt;
&lt;/div&gt;</description><author>pwasiewicz</author><pubDate>Wed, 22 May 2013 15:40:30 GMT</pubDate><guid isPermaLink="false">New Post: Event for updating content type definition 20130522034030P</guid></item><item><title>Closed Unassigned: Double-clicking publish throws exception [19735]</title><link>http://orchard.codeplex.com/workitem/19735</link><description>Please delete this .. my mistake.&lt;br /&gt;Comments: As requested.</description><author>Piedone</author><pubDate>Wed, 22 May 2013 14:42:13 GMT</pubDate><guid isPermaLink="false">Closed Unassigned: Double-clicking publish throws exception [19735] 20130522024213P</guid></item><item><title>New Post: Custom Admin Theme</title><link>https://orchard.codeplex.com/discussions/258854</link><description>&lt;div style="line-height: normal;"&gt;I'm having content part that defines specific behavior for types that use it, so I wanted on one place to define display options in placement.info, as when showing content list types that use this part should not have view and unpublish actions.&lt;br /&gt;
&lt;/div&gt;</description><author>maverik018</author><pubDate>Wed, 22 May 2013 14:31:47 GMT</pubDate><guid isPermaLink="false">New Post: Custom Admin Theme 20130522023147P</guid></item><item><title>New Post: Custom Admin Theme</title><link>https://orchard.codeplex.com/discussions/258854</link><description>&lt;div style="line-height: normal;"&gt;I'm having content part that defines specific behavior for types that use it, so I wanted on one place to define display options in placement.info, as when showing content list types that use this part should not have view and unpublish actions.&lt;br /&gt;
&lt;/div&gt;</description><author>maverik018</author><pubDate>Wed, 22 May 2013 14:31:47 GMT</pubDate><guid isPermaLink="false">New Post: Custom Admin Theme 20130522023147P</guid></item><item><title>New Post: Custom Admin Theme</title><link>http://orchard.codeplex.com/discussions/258854</link><description>&lt;div style="line-height: normal;"&gt;I'm having content part that defines specific behavior for types that use it, so I wanted on one place to define display options in placement.info, as when showing content list types that use this part should not have view and unpublish actions.&lt;br /&gt;
&lt;/div&gt;</description><author>maverik018</author><pubDate>Wed, 22 May 2013 14:31:47 GMT</pubDate><guid isPermaLink="false">New Post: Custom Admin Theme 20130522023147P</guid></item></channel></rss>