从 ASP.NET MVC 控制器重定向到外部 URI [英] Redirect to external URI from ASP.NET MVC controller

查看:39
本文介绍了从 ASP.NET MVC 控制器重定向到外部 URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从操作方法重定向到外部 url,但无法使其正常工作.有人能解释一下我的错误吗?

I'm trying to redirect to external url from an action method but can't get it to work. Can anybody shed some light on my error?

public void ID(string id)
    {
        string url = string.Empty;
        switch (id)
        {
            case "DB2FCB11-579F-4DA2-A68C-A6495B9BAAB5":

                url = "http://www.somesite.com";
                break;
        }
        Response.Redirect(url, true);
    }

谢谢,克里斯

推荐答案

如果您在谈论 ASP.NET MVC,那么您应该有一个返回以下内容的控制器方法:

If you're talking about ASP.NET MVC then you should have a controller method that returns the following:

return Redirect("http://www.google.com");

否则,我们需要有关您在重定向中遇到的错误的更多信息.我会逐步确保该网址不为空.

Otherwise we need more info on the error you're getting in the redirect. I'd step through to make sure the url isn't empty.

这篇关于从 ASP.NET MVC 控制器重定向到外部 URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆