using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
namespace EPiServerSample.HttpModule
{
public class EpiServerUrlModule : IHttpModule
{
public EpiServerUrlModule()
{
}
public void Dispose()
{
}
public void Init(HttpApplication application)
{
application.BeginRequest += new EventHandler(application_BeginRequest);
application.ReleaseRequestState += new EventHandler(InstallResponseFilter);
}
void application_BeginRequest(object sender, EventArgs e)
{
HttpContext context = ((HttpApplication)sender).Context;
// original URL
string url = context.Server.UrlDecode(context.Request.Url.ToString());
context.Items.Add("OriginalUrl", url);
}
private void InstallResponseFilter(object sender, EventArgs e)
{
HttpResponse response = ((HttpApplication)sender).Context.Response;
if (response.ContentType == "text/html" || response.ContentType == "text/plain")
{
response.Filter = new Filter.AjaxPageFilter(response.Filter, (HttpApplication)sender);
}
}
}
}
and...
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Web;
using EPiServer.Core;
namespace EPiServerSample.HttpModule.Filter
{
public class AjaxPageFilter : Stream
{
Stream _responseStream;
long _position;
StringBuilder _responseHtml;
HttpApplication _httpApplication;
public AjaxPageFilter(Stream inputStream, HttpApplication httpApplication)
{
_responseStream = inputStream;
_responseHtml = new StringBuilder();
_httpApplication = httpApplication;
}
public override bool CanRead
{
get { return true; }
}
public override bool CanSeek
{
get { return true; }
}
public override bool CanWrite
{
get { return true; }
}
public override void Close()
{
_responseStream.Close();
}
public override void Flush()
{
_responseStream.Flush();
}
public override long Length
{
get { return 0; }
}
public override long Position
{
get { return _position; }
set { _position = value; }
}
public override long Seek(long offset, SeekOrigin origin)
{
return _responseStream.Seek(offset, origin);
}
public override void SetLength(long length)
{
_responseStream.SetLength(length);
}
public override int Read(byte[] buffer, int offset, int count)
{
return _responseStream.Read(buffer, offset, count);
}
public override void Write(byte[] buffer, int offset, int count)
{
string finalHtml = System.Text.UTF8Encoding.UTF8.GetString(buffer, offset, count);
{
if (EPiServer.Util.FriendlyUrlModule.IsCurrentRequestFriendly)
{
string url = _httpApplication.Context.Request.Url.AbsoluteUri.Replace(_httpApplication.Context.Request.Url.PathAndQuery, "");
url = url.TrimEnd('/') + "/" + EPiServer.Util.FriendlyUrlModule.CurrentUrl.Trim('/') + "/" + "Post.aspx";
url = url.Replace("Post.aspx/Post.aspx", "Post.aspx").Replace("Post.aspxPost.aspx", "Post.aspx");
// Transform the response
if (!String.IsNullOrEmpty(url))
{
finalHtml = Regex.Replace(finalHtml, "\\|\\d+\\|formAction\\|\\|[^\\|]+\\|",
"|" + url.Length.ToString() + "|formAction||" + url + "|",
RegexOptions.IgnoreCase);
int formIndex = finalHtml.ToLower().IndexOf("
Then we've attached the HTTPModule in Web.Config like this:
Hope this will help you with your problems.
/Martin Emanuelsson
Guide Konsult AB
Hi,
I might have found a solution on the big www for this problem. Add the following to you web.config and see if it works.
<httpModules>
<add name=”ScriptModule” type=”System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″/>
</httpModules>
That works for me, or at least has been working for about an hour. First I tried a solution with where I had a separate ajax filter which I found in the old forum. That solution did not work for when a user session timed out.
I found the solution on these two web sites:
http://ranafaisal.wordpress.com/
http://www.dotnetglobe.com/2008/02/sys_02.html
Hope this will work for you,
--Tomas
AjaxPageFilter class (the second one) is somehow corrupted via my browser (cant get the paragraphs right). Could someone send it to me or rewrite it to forum? Thnx
Here's the code for AjaxPageFilter that was mentioned in my previous post:
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Web;
using EPiServer.Core;
namespace TENAOnline.HttpModule.Filter
{
public class AjaxPageFilter : Stream
{
Stream _responseStream;
long _position;
StringBuilder _responseHtml;
HttpApplication _httpApplication;
public AjaxPageFilter(Stream inputStream, HttpApplication httpApplication)
{
_responseStream = inputStream;
_responseHtml = new StringBuilder();
_httpApplication = httpApplication;
}
public override bool CanRead
{
get { return true; }
}
public override bool CanSeek
{
get { return true; }
}
public override bool CanWrite
{
get { return true; }
}
public override void Close()
{
_responseStream.Close();
}
public override void Flush()
{
_responseStream.Flush();
}
public override long Length
{
get { return 0; }
}
public override long Position
{
get { return _position; }
set { _position = value; }
}
public override long Seek(long offset, SeekOrigin origin)
{
return _responseStream.Seek(offset, origin);
}
public override void SetLength(long length)
{
_responseStream.SetLength(length);
}
public override int Read(byte[] buffer, int offset, int count)
{
return _responseStream.Read(buffer, offset, count);
}
public override void Write(byte[] buffer, int offset, int count)
{
string finalHtml = System.Text.UTF8Encoding.UTF8.GetString(buffer, offset, count);
{
if (EPiServer.Util.FriendlyUrlModule.IsCurrentRequestFriendly)
{
string url = _httpApplication.Context.Request.Url.AbsoluteUri.Replace(_httpApplication.Context.Request.Url.PathAndQuery, "");
url = url.TrimEnd('/') + "/" + EPiServer.Util.FriendlyUrlModule.CurrentUrl.Trim('/') + "/" + "Post.aspx";
url = url.Replace("Post.aspx/Post.aspx", "Post.aspx").Replace("Post.aspxPost.aspx", "Post.aspx");
// Transform the response
if (!String.IsNullOrEmpty(url))
{
finalHtml = Regex.Replace(finalHtml, "\\|\\d+\\|formAction\\|\\|[^\\|]+\\|",
"|" + url.Length.ToString() + "|formAction||" + url + "|",
RegexOptions.IgnoreCase);
int formIndex = finalHtml.ToLower().IndexOf("
if (formIndex >= 0)
{
int actionIndex = finalHtml.ToLower().IndexOf("action=\"", formIndex);
if (actionIndex >= 0)
{
int endActionIndex = finalHtml.ToLower().IndexOf("\"", actionIndex + 8);
if (endActionIndex >= 0)
{
finalHtml = finalHtml.Substring(0, actionIndex + 8) + url + finalHtml.Substring(endActionIndex);
}
}
}
}
}
}
// Write the response
byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(finalHtml);
_responseStream.Write(data, 0, data.Length);
}
}
}
Didnt fix my problem. I have .Net 3.5. AjaxControlToolkit.dll v.3.0.20820.16598, System.Web.Extensions v.3.5.0.0. EPiServer v.4.62.0.533.
In my webconfig I have these Ajax definitions (the code button doesnt work,sry)
-----Under system.web->
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
</httpHandlers>
---- under Pages>Controls ->
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
---- under httpmodules ->
<add name="EpiServerUrl" type="AjaxModule.EpiServerUrlModule" />
and registered assembly on the page that uses Ajax
<%@ Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
Namespace="System.Web.UI" TagPrefix="asp" %>
----------------------
It builds fine and works fine, but not in controls like Calendar in UpdatePanel, in which it gives on second click that Sys.WebForms.PageRequestManagerParseErrorException error?