谷歌404和.Net自定义错误页 [英] Google 404 and .Net Custom Error Pages

查看:130
本文介绍了谷歌404和.Net自定义错误页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这问题有两个部分真的那么即使你可以只用一个部分帮助,这将有助于我出去了一下!

我有一个asp.net 2.0的网站自定义的404页。如果没有发现内容的网站与查询字符串此外aspxerrorpath = / mauro.aspx的提供自定义的404页。 404页本身送达的200 HTTP状态要尝试解决此我添加了

 保护无效的Page_Load(对象发件人,EventArgs的发送)
    {
        Response.Status code = 404;
    }

我增加了谷歌小工具,并与它的两个问题。在IE7它不,它应该显示,如果将它添加到内容我对char 79线226点左右得到一个未知错误;如果我把它添加到头部的搜索框出现在内容上方。在Firefox它工作正常。

所以我的问题是:


  1. 如何使小部件出现
    内联?

  2. 如何让我的错误页
    呈现为与原来的404
    命名并作为文件的路径
    要求这样,当我要求
    mauro.aspx我得到的内容
    404页,但用的网址
    mauro.aspx? (我认为我会
    必须做一些URL重写的
    begin_request Global.asax文件,但
    想我在这之前确认
    做傻事)


解决方案

我在Global.asax文件这样处理的404

 保护无效的Application_BeginRequest(对象发件人,EventArgs的发送)
{
    字符串的URL = Request.RawUrl;
    如果((url.Contains(ASPX))及&放大器;!(System.IO.File.Exists(使用Server.Mappath(URL))))
    {
        Server.Transfer的(/错误/ FileNotFound.aspx);
    }
}

现在,如果有人可以帮助我的谷歌小工具,将是伟大的!

This question has two parts really so even if you can help with just one part that will help me out a bit!

I've got an asp.net 2.0 website with a custom 404 page. When content is not found the site serves the custom 404 page with a query string addition of aspxerrorpath=/mauro.aspx. The 404 page itself is served with an http status of 200. To try to resolve this I've added

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.StatusCode = 404;
    }

I added the google widget and have two issues with it. In IE7 it does not display where it should, if I add it to the content I get an "unknown error" on char 79 line 226 or thereabouts; if I add it to the head section the search boxes appear above the content. in Firefox it works fine.

So my issues are:

  1. How do I make the widget appear inline?
  2. How do I make the error page render as a 404 with the original name and path of the file being requested so that when I request mauro.aspx I get the content for the 404 page but with the url of mauro.aspx? (I assume that I will have to do some URL Rewriting in the begin_request global.asax file but would like this confirmed before I do anything silly)

解决方案

I've handled the 404 by doing this in the global.asax file

protected void Application_BeginRequest(object sender, EventArgs e)
{
    string url = Request.RawUrl;
    if ((url.Contains(".aspx")) && (!System.IO.File.Exists(Server.MapPath(url))))
    {
        Server.Transfer("/Error/FileNotFound.aspx");
    }
}

Now, if anyone can help me with the google widget that would be great!

这篇关于谷歌404和.Net自定义错误页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆