当站点中集成ServiceStack.RabbitMQ时快速处理异步请求时,官方建议初始化如下:

public class AppHost : AppHostHttpListenerBase
{
public AppHost() : base("Rabbit MQ Test Host", typeof(HelloService).Assembly) {} public override void Configure(Container container)
{
container.Register<IMessageService>(c => new RabbitMqServer()); var mqServer = container.Resolve<IMessageService>(); mqServer.RegisterHandler<Hello>(ExecuteMessage);
mqServer.Start();
}
}

https://github.com/ServiceStack/ServiceStack/wiki/Rabbit-MQ

而当我们默认将此启动程序放入asp.net站点里的global.asa里:

protected void Application_Start(object sender, EventArgs e)
{
new AppHost().Init();
}
会发现默认的站点里的静态页面无法运行了,经过分析发现:
ServiceStack.HostConfig初始化时,其属性出现问题了
WebHostPhysicalPath = "~".MapServerPath(),
深入看一下MapServerPath的详细实现
public static string MapServerPath(this string relativePath)
{
return HostContext.IsAspNetHost
? relativePath.MapHostAbsolutePath()
: relativePath.MapAbsolutePath();
}
public static bool IsAspNetHost
        {
            get { return ServiceStackHost.Instance is AppHostBase; }
        }

看到这里应该发现了,这个方法判断引起的,因为当前初化的是ServiceStack.AppHostHttpListenerBase,导致HostConfig.WebHostPhysicalPath 的值是不正确的,指向了站点\bin目录了,导致正常的静态资源得不到正确处理。

找到原因了,解决这个问题也就容易多了,直接在上面的初始化方法里加一句:
var cfg = new HostConfig();
cfg.WebHostPhysicalPath = "~".MapAbsolutePath();
SetConfig(cfg);




												

ServiceStack.RabbitMQ在站点中使用时导致静态页面无法正常解析的更多相关文章

  1. 解决echart在IE中使用时,在div中加入postion后图表不显示问题

    <!-- 为ECharts准备一个具备大小(宽高)的Dom --> <div id="main" style="height:400px;width:1 ...

  2. SpringMVC中利用@InitBinder来对页面数据进行解析绑定

    同步发布:http://www.yuanrengu.com/index.php/springmvc-user-initbinder.html 在使用SpingMVC框架的项目中,经常会遇到页面某些数据 ...

  3. 修复Telerik reporting 在网页中使用时的样式

    在ASP.NET 网页或ASP MVC中嵌入Telerik Reporting时,报表出来的样式是有问题的,按扭的位置错位了. 在页面中引入以下CSS文件可以将报表样式修复从而回到正常的报表样式. . ...

  4. SQLite中使用时的数据类型注意

    在使用SQLite时,要注意:在SQLite中的Integer类型,对应在C#中需要使用long类型或者Int64 在使用SQLite时,要注意:在SQLite中存放的日期类型必须是如此:yyyy-M ...

  5. window.location.href 放置在单独的JS文件中使用时问题

    场景:假设当前浏览器地址栏的地址是:http://localhost:8888/SSHBoot/tourist/homeMainAction_signInUI.do, 现在我想在点击按钮时定位到“ht ...

  6. Python中 "+=" 使用时的注意事项

    代码1: >>> l1=range(3) >>> l2=l1 >>> l2+=[4] >>> l1 [0, 1, 2, 4] & ...

  7. UINavigationController和UIScrollView一起使用时导致UIScrollView位置偏移

    iOS7之后,当UIViewController成为UINavigationController的控制视图,UIViewController的控制视图上的第一个子视图是UIScrollView,UIS ...

  8. WebPack系列:Webpack编译的代码如何在tomcat中使用时静态资源路径不对的问题如何解决

    问题:     使用webpack+vue做前端,使用tomcat提供api,然后npm run build之后需要将编译,生成如下文件: |   index.html \---appserver   ...

  9. MUI在项目中使用时遇到的问题的个人分享

    picker 添加年插件问题总结 1. 取消按钮点击事件无法获取 可以获取到取消按钮标签和确定按钮标签 但是只能获取去顶按钮事件,取消点击事件无法获取 通过判断picker的display状态也不能确 ...

随机推荐

  1. ZBar只扫描二维码/条形码

    You can add these codes for ImageScanner scanner.setConfig(0, Config.ENABLE, 0); //Disable all the S ...

  2. hdu4485 B-Casting(mod运算)

    B-Casting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. Android源代码之Gallery专题研究(1)

    前言 时光飞逝,从事Android系统开发已经两年了,总想写点什么来安慰自己.思考了非常久总是无法下笔,认为没什么好写的.如今最终决定写一些符合大多数人需求的东西,想必使用过Android手机的人们一 ...

  4. uva 167 - The Sultan&#39;s Successors(典型的八皇后问题)

    这道题是典型的八皇后问题,刘汝佳书上有具体的解说. 代码的实现例如以下: #include <stdio.h> #include <string.h> #include < ...

  5. sort()排序 collections.sort();

    1.main方法: public class Test { public static void main(String[] args) { /** * * sort()方法详解 * 1.Collec ...

  6. Spring/Hibernate Improved SQL Logging with log4jdbc---reference

    Hibernate provides SQL logging out of the box, but such logging only shows prepared statements, and ...

  7. ubuntu中安装jdk 分类: java 学习笔记 linux ubuntu 2015-07-06 17:49 74人阅读 评论(0) 收藏

    参考文献:ubuntu 13.04 安装 JDK 先去oracle官网下载jdk,这一段我就不赘述了. 下载好之后先解压,解压方式参见 linux常用的压缩与解压缩命令 ,解压之后,将文件剪贴至/us ...

  8. iOS UIKit:TabBar Controller

    1 结构剖析 IOS中的标签导航其实是一个UITabBarController对象,其也是一个Container View Controller.UITabBarController对象创建和管理了一 ...

  9. 读者汇app项目案例源码

    这款app是我花一周左右时间做出来的,一款阅读笑话,段子,糗事,脑筋急转弯,神回复,语录,谜语等的休闲娱乐app,用户除了可以浏览他人发布的内容外,自己也可以发布相关内容,和其他人一同分享有趣的内容, ...

  10. LA 4329(树状数组)

    题目描述: N <tex2html_verbatim_mark>(3N20000) <tex2html_verbatim_mark>ping pong players live ...