[英]ASP.NET IIS7 Dynamic 404 Page
I'm looking for a solution for a dynamic 404 page. 我正在寻找动态404页面的解决方案。
I have a Page404.aspx
page that requests a WebsiteID parameter in the querystring when it loads. 我有一个Page404.aspx
页面,该页面在加载时在querystring中请求一个WebsiteID参数。
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. 假设每个网站在DB中存储了一个不同的404页html,并且在每个页面加载中,它将通过QueryString中的WebsiteID显示正确的html。
Now the tricky thing- How do I redirect the client to the correct 404page, with the CURRENT WebsiteID ? 现在棘手的事情是-如何使用CURRENT WebsiteID将客户端重定向到正确的404页?
Hope I was clear enough. 希望我足够清楚。 Thanks in advance, 提前致谢,
Gal. 加尔
If you don't have a Global.asax, then create one for your website. 如果您没有Global.asax,则为您的网站创建一个。 This assumes that your websites are split up by directory. 假设您的网站按目录划分。
In the new Global.asax file there should be 在新的Global.asax文件中,应该有
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. 您还可以查看这篇文章以获取其他信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.