【发布时间】:2016-08-24 17:52:28
【问题描述】:
我必须从另一个网站获取 html 响应并加载到我的应用程序中。我写了下面的代码,
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
namespace MVC_TEST.Controllers
{
public class DocumentCloudController : Controller
{
public string Index()
{
var result = GetResponse();
return result;
}
private static string GetResponse()
{
var html = string.Empty;
const string url = @"http://localhost/xxxxx/yyyyy/logon.aspx";
var request = (HttpWebRequest)WebRequest.Create(url);
request.AutomaticDecompression = DecompressionMethods.GZip;
using (var response = (HttpWebResponse)request.GetResponse())
{
using (var stream = response.GetResponseStream())
{
if (stream != null)
{
using (var reader = new StreamReader(stream))
{
html = reader.ReadToEnd();
}
}
}
}
return html;
}}
}
}
控件加载正确,但图片、css和js路径映射到相对路径
/xxxx/yyyy/dojo.js ,
/xxxx/style/logon.css,
/xxxx/images/logon.png
在 html 中,我必须将其更改为如下所示的实际 url
http://localhost/xxxx/yyyy/dojo.js ,
http://localhost/xxxx/style/logon.js ,
http://localhost/xxxx/images/logon.png
一个选项是在 html 中找到这些内容替换它。
还有其他选项可以动态更改网址吗? IIS URL Rewrite 模块是否适合我的要求?
请分享你的想法
【问题讨论】:
标签: html asp.net .net asp.net-mvc iis-7