2011-11-28 23 views
5

Tôi đang cố gắng sử dụng trang html đơn giản khi 503 lỗi dịch vụ không khả dụng đến.httperrors trong web.config

Tôi đang sử dụng dưới đây trong system.webservers web.config của

<httpErrors errorMode="Custom"> 
    <remove statuscode="503" substatuscode="-1"> 
    <error statuscode="503" responseMode="File" path="Views/Shared/IISError.htm"> 
</httpErrors> 

này được nt làm việc. Tôi vẫn nhận được trang mặc định IIS khi tôi ngừng ứng dụng của mình.

Tôi đang sử dụng mvc3, ứng dụng dao cạo.

+1

Hãy thử '' –

Trả lời

2

Câu hỏi đặt ra là, bạn có đang sử dụng VisualStudio Development Server hoặc IIS7 Express không?

nếu bạn đang sử dụng Cassini (VSDS) thì bạn nên thử với

<customErrors mode="On" > 
    <error statusCode="503" redirect="/Views/Shared/Error.htm"/> 
</customErrors> 

vì httpErrors là một cấu trúc mới được xử lý chỉ bằng IIS7. Bạn có thể tìm thấy một số thông tin thêm về: What is the difference between customErrors and httpErrors?http://www.iis.net/ConfigReference/system.webServer/httpErrors

+0

Tôi đang sử dụng IIS 7.0 –

+0

How are you nhận bạn IIS để ném 503 ? Nếu bạn đang thực hiện nó thông qua ứng dụng, nó sẽ đi qua trình xử lý Asp.Net. Chỉ thị httpErrors là dành cho nội dung không đi qua Asp.Net – torm

+0

Tôi đang dừng hồ bơi ứng dụng của mình trong IIS. điều này cho tôi thấy trang mặc định 503 thay vì trang của tôi. –

7

Tôi đã mất một thời gian để con số này ra ... nhưng tôi nghĩ rằng điều này có thể giúp bạn:

Trước hết phải cấu hình sai sót trong IIS 7 bạn cần phải làm điều đó bằng cách sử dụng phần sau:

<system.webServer> 
    <httpErrors existingResponse="Replace" defaultResponseMode="Redirect" errorMode="Custom"> 
     <remove statusCode="503"/> 
     <error statusCode="503" responseMode="Redirect" path="Views/Shared/IISError.htm"/>   
    </httpErrors> 
    </system.webServer> 

cấu hình này hoạt động, tuy nhiên bạn có thể nhận được một lỗi cho biết rằng bạn không thể ghi đè lên phần httpErrors, nếu đó là trường hợp, hãy làm theo các bước sau:

  1. Mở C:\Windows\System32\inetsrv\config\applicationHost.config

  2. Thay đổi:

    <section name="httpErrors" overrideModeDefault="Deny" /> 
    

    Để:

    <section name="httpErrors" overrideModeDefault="Allow" /> 
    
1

Dựa trên một trong những bình luận của bạn nó xuất hiện như thể bạn đang dừng hồ bơi ứng dụng của bạn .

Nếu bạn đang dừng nhóm ứng dụng, bạn không thể đặt lỗi tùy chỉnh trong web.config. Bạn sẽ cần phải làm điều đó trong IIS.

1

Trong Mvc 5.1.1 và IIS 7.5, dấu gạch chéo ngược là bắt buộc để biểu thị thư mục con cho chế độ Phản hồi tệp.

C#:

[HttpGet] 
[AllowAnonymous] 
public ActionResult Login() 
{ 
    try 
    { 
     var allowLogin = false; 

     if(allowLogin == false) 
      return new HttpStatusCodeResult(403); 
    } 
} 

Web.config:

<system.web> 
    <!--customErrors tag is not required --> 
</system.web> 
<httpErrors errorMode="Custom" existingResponse="Replace" defaultResponseMode="File" > 
    <remove statusCode="400" subStatusCode="-1" /> 
    <remove statusCode="401" subStatusCode="-1" /> 
    <remove statusCode="403" subStatusCode="6" /> 
    <remove statusCode="403" subStatusCode="-1" /> 
    <remove statusCode="503" subStatusCode="-1" /> 
    <remove statusCode="500" subStatusCode="-1" /> 
    <clear/> 
    <error statusCode="400" subStatusCode="-1" path="ErrorPages\400.html" /> 
    <error statusCode="401" subStatusCode="-1" path="ErrorPages\401.html" /> 
    <error statusCode="403" subStatusCode="6" path="ErrorPages\Restrict.html" /> 
    <error statusCode="403" subStatusCode="-1" path="ErrorPages\403.html" /> 
    <error statusCode="503" subStatusCode="-1" path="ErrorPages\503.html" /> 
    <error statusCode="500" subStatusCode="-1" path="ErrorPages\500.html" /> 
</httpErrors> 
Các vấn đề liên quan