WebPartManager is undefined JavaScript error

R

Richard Priddy

Hello,
I have a webpage that uses URL rewriting to masquerade as many pages. I am
trying to get this page to work with ASP.NET2 web parts.
I will attach any important code at the bottom of this post.

The problem I am having is that when URL rewriting is enabled any controls
that are in WebPartZones cannot be moved minimized or closed. With URL
rewriting disabled all this is possible.

When the page loads and I logon to give me access to the design layout I get
3 JavaScript errors:
"WebPartManager is Undefined"
and two "WebPartManager is undefined" errors

I have been working on this for a number of hours and have been unable to
track down why these errors are occurring.

IHttpModule.cs:
public class UrlRewrite : System.Web.IHttpModule
{
HttpApplication _application = null;
public UrlRewrite() { }

public void Init(System.Web.HttpApplication context)
{ context.BeginRequest += new EventHandler(context_BeginRequest); }

public void Dispose() { }

private void context_BeginRequest(object sender, EventArgs e)
{
System.Web.HttpContext httpContext = HttpContext.Current;
String currentURL = httpContext.Request.Path.ToLower();

string processPath =
currentURL.Substring(httpContext.Request.ApplicationPath.Length).TrimStart('/').ToLower();
string physicalPath =
httpContext.Server.MapPath(currentURL.Substring(currentURL.LastIndexOf("/") +
1));
if (!System.IO.File.Exists(physicalPath))
{
string queryString =
httpContext.Request.ServerVariables["QUERY_STRING"];
string defaultPage = "~/Default.aspx?process=";
if (processPath.EndsWith(".aspx"))
processPath = processPath.Substring(0, processPath.Length -
".aspx".Length);
httpContext.RewritePath(defaultPage + processPath + "&" +
queryString);
} } }
Default.aspx.cs:
protected void Page_PreInit(object sender, EventArgs e)
{

if (!Request.RawUrl.Contains("WebResource.axd"))
{
System.Web.HttpContext httpContext = HttpContext.Current;
string RawURL = Request.RawUrl;

Regex regex = new Regex(
@"(?<URL>.*)\?",
RegexOptions.IgnoreCase
| RegexOptions.Multiline
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);
Match URLMatch = regex.Match(RawURL);
if (URLMatch.Groups["URL"].Success)
{
RawURL = URLMatch.Groups["URL"].Value;

}


Context.RewritePath(RawURL);
}
}
 
R

Richard Priddy

I have finally fixed this problem!

The issue is with WebResource.axd which seems to be a dynamically generated
JavaScript file produced by ASP.NET The issue is with the URL rewriting it
rewrites the path of this file as wel, so when the application runs it
doesn’t include WebResources properly and cannot define WebPartManager/Menu.
So the fix is to check that the file name when rewriting the URLs and ignore
anything with WebResource.axd in the path.

System.Web.HttpContext httpContext = HttpContext.Current;
String currentURL = httpContext.Request.Path.ToLower();
if (!currentURL.Contains("webresource.axd"))
{
/*URL ReWriting here*/
}


Richard Priddy said:
Hello,
I have a webpage that uses URL rewriting to masquerade as many pages. I am
trying to get this page to work with ASP.NET2 web parts.
I will attach any important code at the bottom of this post.

The problem I am having is that when URL rewriting is enabled any controls
that are in WebPartZones cannot be moved minimized or closed. With URL
rewriting disabled all this is possible.

When the page loads and I logon to give me access to the design layout I get
3 JavaScript errors:
"WebPartManager is Undefined"
and two "WebPartManager is undefined" errors

I have been working on this for a number of hours and have been unable to
track down why these errors are occurring.

IHttpModule.cs:
public class UrlRewrite : System.Web.IHttpModule
{
HttpApplication _application = null;
public UrlRewrite() { }

public void Init(System.Web.HttpApplication context)
{ context.BeginRequest += new EventHandler(context_BeginRequest); }

public void Dispose() { }

private void context_BeginRequest(object sender, EventArgs e)
{
System.Web.HttpContext httpContext = HttpContext.Current;
String currentURL = httpContext.Request.Path.ToLower();

string processPath =
currentURL.Substring(httpContext.Request.ApplicationPath.Length).TrimStart('/').ToLower();
string physicalPath =
httpContext.Server.MapPath(currentURL.Substring(currentURL.LastIndexOf("/") +
1));
if (!System.IO.File.Exists(physicalPath))
{
string queryString =
httpContext.Request.ServerVariables["QUERY_STRING"];
string defaultPage = "~/Default.aspx?process=";
if (processPath.EndsWith(".aspx"))
processPath = processPath.Substring(0, processPath.Length -
".aspx".Length);
httpContext.RewritePath(defaultPage + processPath + "&" +
queryString);
} } }
Default.aspx.cs:
protected void Page_PreInit(object sender, EventArgs e)
{

if (!Request.RawUrl.Contains("WebResource.axd"))
{
System.Web.HttpContext httpContext = HttpContext.Current;
string RawURL = Request.RawUrl;

Regex regex = new Regex(
@"(?<URL>.*)\?",
RegexOptions.IgnoreCase
| RegexOptions.Multiline
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);
Match URLMatch = regex.Match(RawURL);
if (URLMatch.Groups["URL"].Success)
{
RawURL = URLMatch.Groups["URL"].Value;

}


Context.RewritePath(RawURL);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top