开发者

ASP.NET IIS7 Dynamic 404 Page

I'm looking for a solution for a dynamic 404 page.

I have a Page404.aspx page that requests a WebsiteID parameter in the querystring when it loads.

Let's say each Website has a different 404 page html stored in DB, and in each page load it will show the correct html by the WebsiteID in the QueryString.

Now the tricky thing- How do I redirect the client to the correct 404page, with the CURRENT WebsiteID ?

Hope I was clear enough. Thanks in advance,

Gal.开发者_开发知识库


If you don't have a Global.asax, then create one for your website. This assumes that your websites are split up by directory.

In the new Global.asax file there should be

protected void Application_Error(Object sender, EventArgs e)
{
   HttpContext ctx = HttpContext.Current;

   Exception exception = ctx.Server.GetLastError ();

if (ex.GetType() == typeof(HttpException))
{
   HttpException httpEx = (HttpException)ex;
   if(httpEx.GetHttpCode() == 404) 
   {

     int websiteID = FindWebsiteID(ctx.Request.Url.ToString());

     string errorPage = string.Format("~/404Page.aspx?={0}",websiteID);

     Response.Redirect(errorPage);
  }
}

public int FindWebsiteID(string url){

//parse the url for the directory and look up the id
//for the website via the directory name

}

you may also check out this article for additional information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜