“无效的URI:无法确定URI的格式。”从Web API调用ASPX页面时

时间:2019-05-29 11:42:50

标签: c# asp.net asp.net-mvc redirect asp.net-web-api

我想从我的方法中调用一个aspx页面,所以我将Redirect()方法用作波纹管:

pubic calsss mainController:ApiController
{
    [HttpPost]
    public void postReport()
    {
         Redirect("/WebForm1.aspx");
    } 
}

但是当我使用它时会显示此异常: 'Invalid URI: The format of the URI could not be determined.'

我的WebForm1.aspx是一个内部页面。 有人可以帮助我解决这个问题吗?

Upadate:

我的项目结构:

enter image description here

2 个答案:

答案 0 :(得分:1)

您可以这样替换代码吗?

return Redirect("~/Webform1.aspx");

答案 1 :(得分:0)

尝试

如果您希望重定向到比当前文件夹高一级的文件夹。

    Redirect("../WebForm1.aspx");

如果您希望重定向到根目录,请使用波浪号(〜)

    Redirect("~/WebForm1.aspx");

示例结果:http://www.yoururl.co.uk/directory1/webform1.aspx