2012-03-13 101 views
1

我正在使用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重定向的任何想法?

回答

1

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