반응형
C # 컨트롤러에서 외부 URL로 리디렉션하는 방법
웹 서비스로 ac # 컨트롤러를 사용하고 있습니다.
그 안에 사용자를 외부 URL로 리디렉션하고 싶습니다.
어떻게하나요?
시도 :
System.Web.HttpContext.Current.Response.Redirect
하지만 작동하지 않았습니다.
컨트롤러의 Redirect () 메서드를 사용합니다.
public ActionResult YourAction()
{
// ...
return Redirect("http://www.example.com");
}
최신 정보
ajax 응답에서 서버 측 리디렉션을 직접 수행 할 수 없습니다. 그러나 새 URL로 JsonResult를 반환하고 javascript로 리디렉션을 수행 할 수 있습니다.
public ActionResult YourAction()
{
// ...
return Json(new {url = "http://www.example.com"});
}
$.post("@Url.Action("YourAction")", function(data) {
window.location = data.url;
});
이 시도:
return Redirect("http://www.website.com");
MVC를 사용하는 경우 Response.Redirect 를 사용하는 대신 RedirectResult 를 사용하는 것이 더 적절할 것입니다.
public ActionResult Index() {
return new RedirectResult("http://www.website.com");
}
참조-https: //blogs.msdn.microsoft.com/rickandy/2012/03/01/response-redirect-and-asp-net-mvc-do-not-mix/
참고 URL : https://stackoverflow.com/questions/9739170/how-to-redirect-to-external-url-from-c-sharp-controller
반응형
'Nice programing' 카테고리의 다른 글
파이썬에서 "방법"이란 무엇입니까? (0) | 2020.11.07 |
---|---|
고유 한 값이있는 순열 (0) | 2020.11.07 |
jQuery를 사용하여 테이블의 tbody에 행 추가 (0) | 2020.11.07 |
특정 클래스가없는 요소를 선택하는 방법 (0) | 2020.11.07 |
Ajax 응답에서 반환 된 JavaScript 함수 호출 (0) | 2020.11.07 |