手动设置响应状态代码 [英] Setting response status code manually

查看:136
本文介绍了手动设置响应状态代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个try catch块来处理我的应用程序错误。我想要一种简单的方法来设置对状态代码403或禁止的响应,然后将用户重定向到登录页面或自定义错误页面。

I have a try catch block to handle an error I am getting with my application. I would like a simple way of setting the response to status code 403 or forbidden and then either redirect the user to the login page or to a custom error page.

我在设置状态代码和重定向时遇到了一些问题。任何人都有一个设置状态代码,然后重定向的例子?

I am having some issue with once setting the status code and the redirect. Anyone have an example of setting the status code and then redirecting?

推荐答案

Response.Status = "403 Forbidden";
Response.Addheader("Location", "http://stackoverflow.com/");

这在C#中,但在大多数语言中概念应该基本相同。

This in C#, but the concept should be pretty much the same in most languages.

这篇关于手动设置响应状态代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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