在ASP.NET MVC 4中的URL重定向移动应用程序

问题描述:

我正在使用ASP.NET MVC 4移动应用程序,其中我尝试重定向到外部网站。然而,它以“错误加载页面”消息失败。在ASP.NET MVC 4中的URL重定向移动应用程序

public void RedirectToGoogle() 
{ 
    Response.Redirect("http://www.google.com"); 
} 

我也看到_Layout.cshtml以下脚本,它是在创建应用程序自动创建。

<script> 
    $(document).bind("mobileinit", function() { 
     // As of Beta 2, jQuery Mobile's Ajax navigation does not work in all cases (e.g., 
     // when navigating from a mobile to a non-mobile page, or when clicking "back" 
     // after a form post), hence disabling it. 
     $.mobile.ajaxEnabled = false; 
    }); 
</script> 

我试着改变$ .mobile.ajaxEnabled为true,但没有成功。

有关如何在ASP.NET MVC 4 Mobile应用程序中进行url重定向的任何想法?

Response.Redirect用于WebForms并使用WebForms页面生命周期。对于MVC,你应该使用return Redirect(“http://www.bing.com”);

我已经在一个移动项目中重现了ASP.NET MVC 4/Beta的问题。这是一个CORS(跨源资源共享)问题。请参阅http://www.webdavsystem.com/ajax/programming/cross_origin_requests

将F12开发人员工具用于Fiddler以查看问题。

EC7118:XMLHttpRequest为http://www.bing.com/需要跨源资源共享(CORS)。 localhost:52137

SEC7119:XMLHttpRequest for http://www.bing.com/需要CORS预检。 localhost:52137

+0

什么是解决方案?我收到以下错误:SEC7118:XMLHttpRequest需要https://docs.google.com/spreadsheets/d/1KcdPEYjmvemndMfJv3IAIK5HAX2xs267mvtt6WHGkC8/edit?usp=sharing所需的跨源资源共享(CORS)。 SEC7119:https://docs.google.com/spreadsheets/d/1KcdPEYjmvemndMfJv3IAIK5HAX2xs267mvtt6WHGkC8/edit?usp=sharing所需的XMLHttpRequest需要CORS预检。在Access-Control-Allow-Origin标题中找不到SEC7120:Origin http:// localhost:18591。 SCRIPT7002:XMLHttpRequest:网络错误0x80070005,访问被拒绝。 – AKS 2014-09-24 11:15:43