如何在mvc中处理404错误?

时间:2017-09-26 05:56:18

标签: asp.net-mvc asp.net-mvc-4 c#-4.0 error-handling

我正在尝试处理MVC中的404错误,所有其他错误都是使用角度处理,因此不必担心其他异常。

我正在处理Global.asax页面中的404错误,如此

 protected void Application_Error()
        {
            // if (Context.IsCustomErrorEnabled)
             ShowCustomErrorPage(Server.GetLastError());
        }
        private void ShowCustomErrorPage(Exception exception)
        {
            var httpException = exception as HttpException ?? new HttpException(500, "Internal Server Error", exception);

            Response.Clear();
            var routeData = new RouteData();
            routeData.Values.Add("controller", "ErrorHandling");
            routeData.Values.Add("fromAppErrorEvent", true);

            switch (httpException.GetHttpCode())
            {
                case 404:
                    routeData.Values.Add("action", "HttpError404");
                    break;
            }

            Server.ClearError();

            IController controller = new ErrorHandlingController();
            controller.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));
        }

但是当404错误发生时,执行方法

  

controller.Execute(new RequestContext(new HttpContextWrapper(Context),   的RouteData));

呈现页面的html而不是页面本身,如何进行更改以便我能够呈现页面本身而不是页面的html。

1 个答案:

答案 0 :(得分:1)

在您的网络配置上编写以下代码

import PyCapture2
import cv2
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image

bus = PyCapture2.BusManager()
numCams = bus.getNumOfCameras()
camera = PyCapture2.Camera()
uid = bus.getCameraFromIndex(0)
camera.connect(uid)
camera.startCapture()

while True:
    image = camera.retrieveBuffer()
    row_bytes = float(len(image.getData())) / float(image.getRows());
    cv_image = np.array(image.getData(), dtype="uint8").reshape((image.getRows(), image.getCols()) );
    cv2.imshow('frame',cv_image)
    cv2.waitKey(0)