标签: http-status-code-404

如果查询字符串丢失,给用户404?

说我需要一个查询字符串; 例如"itemid".如果由于某种原因缺少该查询字符串,我应该给用户一个200错误页面还是"404 Not Found"?

我赞成404,但我不太确定.

http http-headers http-status-code-404

2
推荐指数
1
解决办法
1306
查看次数

ASP.NET应用程序错误覆盖404?

我使用Application_Error事件捕获并记录我的应用程序中的错误。记录错误,然后显示友好的错误屏幕:

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        Dim ex As New Exception( _
            String.Format("Error on page: '{0}'.", HttpContext.Current.Request.Url), _
            Server.GetLastError())

        Dim uid As Guid = Log.FatalError(ex)
        Server.Transfer(String.Concat("~\\GlobalError.aspx?error=", uid))
End Sub
Run Code Online (Sandbox Code Playgroud)

在我的web.config中,我有:

<customErrors mode="On" defaultRedirect="GlobalError.aspx">
  <error statusCode="404" redirect="PageNotFound.aspx" />
</customErrors>
Run Code Online (Sandbox Code Playgroud)

每当用户尝试加载不存在的页面时,他们都会获得GlobalError.aspx页面,而不是PageNotFound.aspx页面。我查看了Application_Error事件,发现Response StatusCode为200,而服务器的最后一个错误是“找不到页面'foo.aspx'”。

我需要怎么做才能使其正常工作?

asp.net error-handling web-config http-status-code-404

2
推荐指数
1
解决办法
3345
查看次数

CodeIgniter:将参数传递给控制器​​时找不到页面?

我正在尝试将参数传递给codeigniter中的控件,但是我找不到404页面错误,我没有得到它,我做了导游所说的:http://codeigniter.com/user_guide/general/ controllers.html#passinguri

当我删除索引函数中的参数并只访问控制器一切正常,但我无法传递值...

以下是我尝试发送参数的代码:

HTTP:// mysite的/ 123

<?php
class Main extends Controller {

    function index($username) {

        echo $username;

    }

}
?>
Run Code Online (Sandbox Code Playgroud)

如何从codeigniter获取有关此错误的更多信息?

谢谢.

php codeigniter codeigniter-url http-status-code-404

2
推荐指数
2
解决办法
1万
查看次数

如何更改Asp.Net中customErrors页面的默认行为

我使用Asp.Net 4和C#.

我想知道如何更改Asp.Net的默认beahviour customErrors.

在我的Web.Config文件中,我使用此设置.

    <customErrors mode="On" defaultRedirect="/ErrorPages/Oops.aspx">
        <error statusCode="404" redirect="/ErrorPages/404.aspx" />
    </customErrors>
Run Code Online (Sandbox Code Playgroud)

正如您所期望的那样,如果找不到页面,则会在Web.Config中指定的自定义页面中进行重定向.


请求页面:

http://localhost:1372/nopagehere
Run Code Online (Sandbox Code Playgroud)

结果页面:

http://localhost:1372/ErrorPages/404.aspx?aspxerrorpath=/nopagehere
Run Code Online (Sandbox Code Playgroud)

当我分析结果页面的Http Header时,我可以看到:

  • 找不到页面时的404状态
  • 新创建的URL的302状态

我想以这种方式改变这种行为:

知道怎么做吗?谢谢你的时间.

html c# asp.net http-status-code-404

2
推荐指数
1
解决办法
250
查看次数

禁用对包含文件的访问

我有一个小问题..

我想禁用直接访问我包含的文件.(例如header.tpl.php,footer.tpl.php,confic.inc.php,db-connect.inc.php等.)

但首先让我解释一下我想要做什么,我想要允许访问我所包含的文件(index.php)并禁用带有404标题的文件以便直接访问.

现在我发现了一些很酷的php片段并对其进行了修改(404标题和404包含)

在我的index.php中是这段代码:

define('MY_APP',true);
Run Code Online (Sandbox Code Playgroud)

在我的模板文件中是这段代码:

if(!defined('MY_APP')) {
header('HTTP/1.1 404 Not Found');
include('./../error/404.php');  
die; }
Run Code Online (Sandbox Code Playgroud)

你看到这个代码有任何安全性或其他问题吗?

最好的问候bernte

php include http-status-code-404

2
推荐指数
1
解决办法
1209
查看次数

从局部视图重定向到Codeigniter中的show_404

我在CodeIgniter中使用HMVC模式.我有一个控制器通过modules :: run()函数加载2个模块,并将参数传递给每个模块.

如果任何一个模块与传递的参数不匹配,我想调用show_404().它可以工作,但它在我现有的模板中加载了错误页面的完整HTML,因此HTML中断并且看起来很糟糕.我想我希望它重定向到错误页面,因此它不会运行第二个模块.有没有办法做到这一点,而不是改变URL?

是否可以在不更改URL的情况下从模块重定向到show_404()?

这是一个简单的例子,说明发生了什么:

www.example.com/users/profile/usernamehere

url在用户控制器中调用此函数:

function profile($username)
{
    echo modules::run('user/details', $username);
    echo modules::run('user/friends', $username);
}
Run Code Online (Sandbox Code Playgroud)

运行这些模块,查看用户是否存在:

function details($username)
{
    $details = lookup_user($username);
    if($details == 'User Not Found')
        show_404(); // This seems to display within the template when what I want is for it to redirect
    else
        $this->load->view('details', $details);
}

function friends($username)
{
    $details = lookup_user($username);
    if($friends == 'User Not Found')
        show_404(); // Redundant, I know, just added for this example
    else
        $this->load->view('friends', $friends);
}
Run Code Online (Sandbox Code Playgroud)

我想有一个更好的方法,但我没有看到它.有任何想法吗?

codeigniter hmvc http-status-code-404

2
推荐指数
1
解决办法
2万
查看次数

如果f:viewParam/converter返回null,如何将人员发送到404页面?

假设你有一个带有视图参数的页面,比如 /widgets?widgetId=1

    <f:metadata>
        <f:viewParam
            name="widgetId"
            value="#{widgetIdMB.widgetId}"
            converter="#{widgetIDConverter}" />
    </f:metadata>
Run Code Online (Sandbox Code Playgroud)

所以,少说你的转换器抛出一个ConverterException,因为有人试图导航到 /widgets?widgetId=1000000,这在数据库中是不存在的.有没有办法在发生这种情况时将此人发送到404页面?

编辑:

我使用转换器来转换值.如果无法在数据库中查找该值,则转换器将返回null,而不是抛出ConverterException.

然后我使用验证器.验证器将抛出validationexception,但在调用omnifaces实用程序类之后不会:Faces.responseSendError(404, "Not Found");

这似乎是关注点分离的最佳实现.

jsf converter http-status-code-404 jsf-2

2
推荐指数
1
解决办法
956
查看次数

Expressjs - 所有路线都是404

在My Express App中,由于某种原因,所有路由都返回404.

Server.js

/**
 * Module dependencies
 */

var express = require('express')
var passport = require('passport')
var env = process.env.NODE_ENV || 'development'
var config = require('./config/config')[env]
var mongoose = require('mongoose')
var fs = require('fs')

require('./helpers')
require('express-namespace')

mongoose.connect(config.db)

// Bootstrap models
fs.readdirSync(__dirname + '/app/models').forEach(function (file) {
  if (~file.indexOf('.js')) require(__dirname + '/app/models/' + file)
})

// Bootstrap passport config
require('./config/passport')(passport, config)

var app = express()

// Bootstrap application settings
require('./config/express')(app, config, passport)

// Bootstrap routes
require('./config/routes')(app, passport)

// Start the app …
Run Code Online (Sandbox Code Playgroud)

javascript url-routing node.js http-status-code-404 express

2
推荐指数
1
解决办法
4895
查看次数

为HttpURLConnection获取404

我在Heroku中部署了一个服务,生成pdf文件输出.当我点击浏览器中的URL时,我可以下载pdf文件(我没有提示保存(根据我的要求),它会自动保存到代码中的已定义路径).所以服务已经开始并且可用.但是当我使用HttpURLConnection访问它时,我收到404错误..任何人都可以帮我解决这个问题吗?

以下是我访问的链接:http: //quiet-savannah-7144.herokuapp.com/services/time/temp

以下是部署在Heroku服务器中的服务代码:

@jawax.ws.rs.core.Context
ServletContext context;

@GET
@path("/temp")
@Produces("application/pdf")
public Response getPdf() throws IOException{
  InputStream is = context.getResourceAsStream("/static/temp.pdf");
  ResponseBuilder res = Response.ok(is);
  res.header("Content-Disposition","attachment; filename=temp.pdf");
  return res.build();
}
Run Code Online (Sandbox Code Playgroud)

注意:我的文件位于webapp/static/temp.pdf

客户端代码如下:

 try {
         URL url = new URL("http://quiet-savannah-7144.herokuapp.com/sevices/time/temp");
         HttpURLConnection conn = (HttpURLConnection) url.openConnection();
         conn.setDoOutput(true);
         conn.setRequestMethod("GET");
         conn.setRequestProperty("Content-Type", "application/json");
         int code = conn.getResponseCode();
         System.out.println("code>>"+code+"<<");
         if (conn.getResponseCode() == 200) {
            System.out.println("*************************done****************************");
            InputStream inputStream = conn.getInputStream();
            OutputStream output = new FileOutputStream("D:/copyOfTest.pdf");
            byte[] buffer = new byte[1024];
            int bytesRead;
            while ((bytesRead = inputStream.read(buffer)) != …
Run Code Online (Sandbox Code Playgroud)

java android heroku httpurlconnection http-status-code-404

2
推荐指数
1
解决办法
9242
查看次数

找不到资源集合的最合适的HTTP状态是什么?

我们的应用程序不直接处理资源,或者支持关于创建,更新,删除资源的各种HTTP动词.我们主要使用"finder"方法返回一组资源.所以我们可能有一个URL /users?firstName=john但不是/users/1.

我们正在讨论的问题是,如果没有找到名字为"john"的用户,那么最合适的HTTP状态代码是什么.我的观点是应返回204表示空集合,但不返回404,因为集合本身不是资源,因此"未找到资源"不是有效响应.RFC 3986,第3.4节说 -

查询组件包含非分层数据,与路径组件(第3.3节)中的数据一起用于标识资源...

关于资源的集合没有任何说法.

思考?

rest http http-status-code-404

2
推荐指数
1
解决办法
150
查看次数