asp.net-mvc - 如何在 Asp.net 中修复端口号

标签 asp.net-mvc iis webforms web-hosting

我在一个解决方案中有两个不同的项目

1. Asp.net项目
2. Mvc项目

在 Asp.net URL 中:http://localhost:54172/View/Dashboard.aspx
在 Mvc URL 中:http://localhost:54177/EmployeeDetail/Index?Id=1

Asp.Net 端口 - 54172
MVC 端口 - 54177

现在我想将 asp.net 项目重定向到 mvc 项目,但由于端口号更改重定向未执行

我想为两个项目修复相同的端口号

我该怎么做才能修复项目和重定向的端口号才能顺利进行?

最佳答案

我的解决方案在这里,
Asp.net 和 mvc 应用程序都将托管在不同的帖子中,因此我们可以为两者修复端口 Asp.net & mvc 并允许反之亦然。该端口将在 web.config 中设置

Asp.Net 项目

Asp.Net 中为 Web.Config 中的 MVC 修复端口, asp.net 应该在这里设置 Mvc 项目端口

<appSettings>
     <add key="MvcApplication" value="http://localhost:54177" />  
</appSettings>

在需要的地方访问页面中的web.config 字符串

ConfigurationManager.AppSettings["MvcApplication"].ToString()<br>

母版页中使用该字符串

<li><a class="nav-link" href="<%= GetUrl() %>" >Add User</a>      

MasterPage.Master.cs 中的 GetUrl 中设置动态 url

    protected string GetLink()
    {
        return ConfigurationManager.AppSettings["MvcApplication"].ToString() + "/UserDetail/Index";
    }

MVC 项目

在 Web.Config 中为 Asp.Net 修复 MVC 中的端口, mvc要设置asp.net项目端口

 <appSettings>    
     <add key="AspDotNetApplicaiton" value="http://localhost:54172" />
</appSettings>

在需要的地方访问页面中的web.config 字符串

System.Configuration.ConfigurationManager.AppSettings["AspDotNetApplicaiton"].ToString()

布局页面中使用该字符串

@{
    var AspDotNetProject = System.Configuration.ConfigurationManager.AppSettings["AspDotNetApplicaiton"].ToString();
 }

在 View 超链接中使用该网络配置字符串

 <li><a href="@AspDotNetProject/View/ContactUs.aspx">Conatact Us</a></li>

用户 Controller 中的网络配置字符串

 string redirectUrl = Convert.ToString(ConfigurationManager.AppSettings["AspDotNetApplicaiton"].ToString() + "/View/Dashboard.aspx");       
 return Redirect(redirectUrl);

这里我们可以实现重定向Asp.net webform到不同项目的mvc!!

谢谢

关于asp.net-mvc - 如何在 Asp.net 中修复端口号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55495946/

相关文章:

c# - IIS 7.5 : unable to login 中的 MVC5 与 Windows 身份验证

c# - 使用 -autofac 找不到任何构造函数

c# - 如何将多个 ScriptBundle 捆绑到一个新的 ScriptBundle

c# - 是否可以从 ASP.NET 路由推断站点地图?

iis - ASP.NET Core 2.2(发布版)产生错误并停止 w3wp

c# - 从之前手动创建的文本框数组中调用 textbox[i]

c# - 如何生成具有 Name 属性而不是 Id 的链接

iphone - Web 服务器和游戏服务器有什么区别?

amazon-web-services - 使用 CloudFormation 在 EC2 上设置 IIS

wcf - 激活 WCF 服务期间出现 FileLoadException