简体   繁体   English

在Web Api控制器中创建一个指向MVC项目控制器的网址

[英]Create a Url in Web Api controller that points to MVC project controller

I have take over a web application and it has the web api and mvc controllers separated into two projects. 我已经接管了一个Web应用程序,它已将Web api和mvc控制器分为两个项目。 The Web Api website has its own base api url localhost:0000 and the mvc website as localhost:1111. Web Api网站具有自己的基本api URL localhost:0000,而mvc网站为localhost:1111。 I am generating a click through link that goes out in an email with the intent to return the user to registration page which is on the mvc website. 我正在生成一个点击后到达链接,该链接出现在电子邮件中,目的是使用户返回mvc网站上的注册页面。 Right now my only option is to do this from the webApi controller however when I generate a link using Url.Link or Url.Content I always get the WebApi localhost:0000 url. 现在,我唯一的选择是从webApi控制器执行此操作,但是当我使用Url.Link或Url.Content生成链接时,我总是会得到WebApi localhost:0000 url。 How do I get the MVC localhost:1111 Url? 我如何获得MVC localhost:1111网址?

-- I left my original question as is -- -我保留了原来的问题-

I think I need to explain this one more clearly... sorry 我想我需要更清楚地解释这一点...对不起

I am generating a Url on my WebApi controller in a website with the url 'localhost:0000' doing something like this 我正在使用网址'localhost:0000'在网站上的WebApi控制器上生成一个网址,该操作如下

invite.ReturnUrl = Url.Link("defaultApi", new { controller = "Account", action = "Register", icode = invite.Id});

OR 要么

invite.ReturnUrl = Url.Content("/Account/Register?icode=" + invite.Id);

I want the created url, however, to use my projects MVC website's base url of "localhost:1111" 我希望创建的URL使用我的项目MVC网站的基本URL“ localhost:1111”

How do I go about this? 我该怎么办?

它不是那么优雅...但这应该可以工作:

invite.ReturnUrl = new UriBuilder(Request.RequestUri.Scheme, Request.RequestUri.Host, 1111, "myApplication/Account/Register?icode=" + invite.Id).ToString();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM