简体   繁体   English

从MVC 4控制器重定向到.aspx页

[英]Redirect to an .aspx page from a MVC 4 Controller

I am pretty new to MVC and have been struggling with re directing between the various pages. 我对MVC还是很陌生,一直在重新引导各个页面之间苦苦挣扎。 I am trying to redirect to an aspx web forms page in the project root folder from am Controller. 我正在尝试从am Controller重定向到项目根文件夹中的aspx Web表单页面。

Below are the solutions I tried: 以下是我尝试的解决方案:

  1. public RedirectResult redirectToAspx() { return Redirect("~/Buffer.aspx"); 公共RedirectResult redirectToAspx(){返回Redirect(“〜/ Buffer.aspx”); } }

  2. return Redirect("~/Buffer.aspx"); 返回Redirect(“〜/ Buffer.aspx”);

  3. Taking out the 取出

    handlers 处理器

    remove name="BlockViewHandler"/> 删除名称=“ BlockViewHandler” />

    add name="BlockViewHandler" path=" " verb=" " preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" /> 添加名称=“ BlockViewHandler”路径=“ ”动词=“ ” preCondition =“ integratedMode” type =“ System.Web.HttpNotFoundHandler” />

    /handlers /处理器

    from System.WebServer 从System.WebServer

1 and 2 work when I run the project on my local machine but does not work when deploying onto Intranet IIS 7. Any ideas on why the redirect is being blocked would be greatly helpful? 当我在本地计算机上运行项目时,图1和图2可以工作,但是当部署到Intranet IIS 7上时,则不能工作。关于阻止重定向的任何想法都将大有帮助?

You can add Error method in global file to find inner exception. 您可以在全局文件中添加Error方法以查找内部异常。

put debug point on exception line and got what is actual error on web server. 将调试点放在异常行上,然后得到Web服务器上的实际错误。

also you should check mime type for handler on web server IIS Click here . 你也应该检查MIME类型的Web服务器IIS处理程序请点击这里

protected void Application_Error(object sender, EventArgs e)
        {
            Exception exception = Server.GetLastError();
            Response.Clear();

            HttpException httpException = exception as HttpException;

            if (httpException != null)
            {
                string action;
                switch (httpException.GetHttpCode())
                {
                    case 404:
                        // page not found
                        action = "HttpError404";
                        break;
                    case 500:
                        // server error
                        action = "HttpError500";
                        break;
                    default:
                        action = "Index";
                        break;
                }

                // clear error on server
                Server.ClearError();

                Response.Redirect(String.Format("~/Error/{0}/?message={1}", action, exception.Message));
            }
        }

also you can do <customErrors mode="Off" /> in web.config to find error on web page. 您也可以在web.config中执行<customErrors mode="Off" />以在网页上查找错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM