![](/img/trans.png)
[英]How can I check if a drive was successfully mapped with net use in C#?
[英]How can I use existingResponse=“Auto” successfully?
所以我從我的MVC網絡應用程序返回詳細的400錯誤響應。 設置existingResponse =“PassThrough”有效,但這不是我想要的。 我不想公開所有的失敗,我只想在我有自定義響應時公開它們。
自動,默認設置,但我故意設置它。 但是,文檔說必須設置“SetStatus”標志,但我不知道如何做這樣的事情。 我編寫了以下四種控制器方法來測試它,只有BadRequestD工作。 其他人設置狀態代碼和狀態就好了,但是正文內容是“錯誤請求”。
public ActionResult BadRequestA()
{
Response.StatusCode = 400;
return Content("weeeeee");
}
public ActionResult BadRequestB()
{
Response.Status = "400 U DUN MESSED UP";
return Content("weeeeee");
}
public ActionResult BadRequestC()
{
Response.Status = "400 U DUN MESSED UP";
Response.StatusCode = 400;
return Content("weeeeee");
}
public ActionResult BadRequestD()
{
Response.StatusCode = 400;
Response.TrySkipIisCustomErrors = true;
return Content("weeeeee");
}
但是,文檔說必須設置“SetStatus”標志,但我不知道如何做這樣的事情
它實際上是在討論IIS C ++ SDK中IHttpResponse::SetStatus
方法的fTrySkipCustomErrors
標志/參數(請參閱我在此處添加到文檔底部的注釋)。 但在ASP.NET中,標志顯示為Response.TrySkipIisCustomErrors
。 所以根據:
http://www.iis.net/configreference/system.webserver/httperrors
Auto =僅在設置了SetStatus標志時才保持響應不變
我希望看到IIS用自己的html錯誤頁面內容替換響應(你可以配置那些內容是什么),除非你設置:
Response.TrySkipIisCustomErrors = true;
這就是你所看到的。
其他相關的信息,在MVC5中,它似乎就像那個標志是真的一樣,即使它對於未在WebForms中看不到的未捕獲的異常是假的。 作為Global.asax中的一種解決方法,我是:
protected void Application_Error()
{
var error = Server.GetLastError();
Server.ClearError();
//code to log error here
var httpException = error as HttpException;
Response.StatusCode = httpException != null ? httpException.GetHttpCode() : (int)HttpStatusCode.InternalServerError;
}
如果您需要具有4xx http狀態的自定義響應,並且仍希望使用自定義錯誤頁面,那么您應該執行以下操作:
existingResponse="Auto"
; TrySkipIisCustomErrors = true
(返回4xx狀態和內容的一個); Application_Error()
- Server.ClearError()
)並重新設置狀態代碼( Reponse.StatusCode = ((HttpException)Server.GetLastError()).GetHttpCode()
) 很遺憾,IIS團隊沒有為特定的狀態代碼實現existingResponse
屬性,因此不可能僅針對一個(或幾個)代碼使用existingResponse="PassThrough"
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.