• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
成为自己最想成为的那种人
博客园    首页    新随笔    联系   管理    订阅  订阅
在ASP.NET MVC 框架中调用 html文件及解析get请求中的参数值

  在ASP.NET MVC 框架中调用 html文件:

    public ActionResult Index()
    {
      using (StreamReader sr = new StreamReader(Path.Combine(HttpRuntime.AppDomainAppPath,"index.html")))
      {
        String htmlContent = sr.ReadToEnd();
        return Content(htmlContent);
      }
    }

扩展:

  如果要调用的html文件是网站的首页(即index.html),其实还有另一些实现方法,比如在global.asax文件中加入以下代码(需要重新编译、发布):

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
      if (Context.Request.FilePath == "/") Context.RewritePath("index.html");
    }

  扩展内容参考于:http://blog.sina.com.cn/s/blog_64008ed70101nnfb.html

二、

  解析 get 请求中的参数值(之前在处理微信公众号的时候需要返回微信发起的一个get请求中的一个参数)

    public void WXtext()
    {
      Response.ContentType = "text/plain";
      string echostr = Request.QueryString["echostr"];


      Response.Write(echostr);
    }

 

posted on 2017-12-14 09:11  遇见未来  阅读(439)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3