asp.net – 从RouteBase.GetVirtualPath返回绝对路径

public class Customroute : RouteBase
{
    public override VirtualPathData GetVirtualPath(RequestContext requestContext,RouteValueDictionary routeValues)
    {
        var virtual_path_data = new VirtualPathData( this,"http://example.com" );

        return virtual_path_data;
    }
}

ASP.NET自动似乎在从VirtualPathData返回的任何(绝对)路径中添加一个前导斜杠,在此示例中返回/http://example.com.

题:

>是否可以通过RouteBase系统生成绝对URL?
>如果不是:什么是最不丑的黑客,所以它适用于Url.Action,RedirectToAction和我不知道的其他用例.

背景

我编写了一个基于XML的路由引擎,它支持多个域名.因此,当我生成仅在其他域上可用的URL时,我想生成一个绝对URL,包括域名.

<host name="exm.com" controller="ShortUrl">
    <parameter name="code" action="Redirect" />
</host>  

<host name="*" default="example.com" controller="Home" action="Index">
    <x name="demo" controller="Home" action="Demo" />
    <x name="comments" controller="Comment" action="List">
        <x name="write" action="Write" />
        <x name="delete" action="Delete" />
    <x>
</host>

导致组合如下:

Url.Action(“Demo”,“Home”)

http://example.com/demo

Url.Action(“写”,“评论”)

http://example.com/comments/write

Url.Action(“Redirect”,“ShortUrl”,new {code =“gH8x”})

http://exm.cm/gH8x

请注意,example.com和exm.com都指的是相同的应用程序IP,并在应用程序中路由.

解决方法

这是一篇关于某人的博客文章,似乎有关于你正在尝试做什么的说明. MVC Domain Routing

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....