2015-06-19 9 views
5

Bir sorunum var. Kullanıcıyı MVC eyleminden http olmayan URL'ye yönlendirmeyi denediğimde, şu döndürür:Yönlendirme "Nesne" ye taşındı "

Nesne buraya taşındı. (Fiddler'dan)

Tam yanıt: (sözde kodu ile)

HTTP/1.1 301 Moved Permanently 
Cache-Control: private 
Content-Type: text/html; charset=utf-8 
Location: myGame-app://test.somespecificdata 
Server: Microsoft-IIS/8.0 
X-AspNetMvc-Version: 4.0 
X-AspNet-Version: 4.0.30319 
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcUGlvdHJcRGVza3RvcFxUYWtlc0NhcmVcVGFrZXNDYXJlXERvY3RvcnNcRWRvY3RvclxDb25zdWx0YXRpb25cMTkx?= 
X-Powered-By: ASP.NET 
Date: Thu, 18 Jun 2015 18:19:35 GMT 
Content-Length: 457 

<html><head><title>Object moved</title></head><body> 
<h2>Object moved to <a href="myGame-app%3a%2f%2ftestprotocol.somespecificdata">here</a>.</h2> 

<!-- Visual Studio Browser Link --> 
<script type="application/json" id="__browserLink_initializationData"> 
    {"appName":"Firefox"} 
</script> 
<script type="text/javascript" src="http://localhost:53098/4c9c75263d91451fa797f9041e4bd0f3/browserLink" async="async"></script> 
<!-- End Browser Link --> 

</body></html> 

Benim eylemi:

[HttpGet] 
public ActionResult Consultation(int id) 
{ 
     //.. specific business logic 
     if(IsMobile()){ 
      return RedirectPermanent("myGame-app://test.somespecificdata"); 
     } 
     else{ 
      return View("AboutGame", SomeSpecificModel); 
     } 
} 

Aynı durum return Redirect() yerine return RedirectPermanent() beraberdir.

Temel amacım, mobil tarayıcıyı kullanan bir kullanıcıyı özel protokolle (http değil) URL'ye yönlendirmektir. Bu özel protokol (myGame-app://) mobil uygulamamı according to this Stack discussion çalıştırıyor. Bunu Object moved to here bilgi olmadan nasıl başarabilirim?

Selamlar

cevap

0

Yönlendirme/RedirectPermanent yöntemleri -HTML "burada hareket" içeren yanıta bir gövde ekleyin. bir "boş" yanıtı sadece yanıtı kendiniz ayarlamak istiyorsanız:

HttpContext.Current.Response.Redirect("url", false); 
HttpContext.Current.Response.StatusCode = 301; 
HttpContext.Current.ApplicationInstance.CompleteRequest(); 

bundan sonra senin mantığın geri kalanı çalıştırılır unutmayın, bu yüzden başka şey olmadığından emin (filtreleri vs.) yapmak yanıtını yönlendirebilir Bunu ayarladıktan sonra tekrar olur.

İlgili konular