且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否可以使用ASP.NET的文字控件显示.html文件?

更新时间:2023-02-15 21:53:01

试试这个:



 public void bindDischargeContent()
{
string urlAddress =Your Daynamic URL; // System.Configuration.ConfigurationManager.AppSettings [DisChargeSiteUrl];
HttpWebRequest request =(HttpWebRequest)WebRequest.Create(urlAddress);
HttpWebResponse response =(HttpWebResponse)request.GetResponse();
if(response.StatusCode == HttpStatusCode.OK)
{
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = null;
if(response.CharacterSet == null)
{
readStream = new StreamReader(receiveStream);
}
else
{
readStream = new StreamReader(receiveStream,Encoding.GetEncoding(response.CharacterSet));
}
string data = readStream.ReadToEnd();
LitForOtherWebsite.Text = data;
response.Close();
readStream.Close();
}
}







HTML部分:

< asp:Literal ID =LitForOtherWebsiterunat =server>< / asp:Literal> 



请投票!!


尝试:

  const   string  virtualPath =  〜/ Contents / sample.html; 
string physicalPath = Server.MapPath(virtualPath);
display_html.Text = System.IO.File.ReadAllText(physicalPath);



但要记住来自F-ES Sitecore的评论:如果文件你正在加载的是一个完整的文档,而不是一个HTML片段,然后你就会遇到问题。



如果你只想删除边框你可以这样做:$ $ $ $ $> iframe / span> 样式 >
iframe .无缝 {
background-color 透明;
border 0px none transparent;
padding :跨度> 0px;
溢出 hidden;
}
< / style >

< iframe class = 无缝 frameborder = 0 allowtransparency = true scrolling = no src = 内容/ sample.html > < / iframe >



HTML5 iFrame无缝属性 - 堆栈溢出 [ ^ ]


I'm trying to "display" my .html file on my web page using literal. To be honest I make it work using iframe but the only reason I'm not going to use iframe is that every time it loads my .html file, the iframe tends to have scroll and borders and gray background. I thought I can fix it by using formborder or formBorder set to 0, scroll="non" and set it's background-color to white but unfortunately, none of it worked. All I wanted to do is to display my .html on my web page without these borders, scrolls and unchanged background color. I read some articles that I can use asp.net control literal to display my .html file but all of them didn't showed the process on how to do so.

I'll be pleased and grateful to you if you could make some suggestion/s or solution/s to my problem.

Cheers~

Note: my sample.html is a document converted from sample.rtf. I thought I can display a .html to my page.

What I have tried:

On My Server

Note: I want to keep my code from behind since I'll be filling the literal soon with the path coming from my database and I want my string file_location to catch that before passing it on literal control.

protected void Page_Load(object sender, EventArgs e)
        {
           string file_location = "Contents/sample.html";
        }



On my Client

<asp:Literal ID="display_html" runat="server"></asp:Literal>

Try This:

public void bindDischargeContent()
        {
            string urlAddress = "Your Daynamic URL";// System.Configuration.ConfigurationManager.AppSettings["DisChargeSiteUrl"];
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlAddress);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            if (response.StatusCode == HttpStatusCode.OK)
            {
                Stream receiveStream = response.GetResponseStream();
                StreamReader readStream = null;
                if (response.CharacterSet == null)
                {
                    readStream = new StreamReader(receiveStream);
                }
                else
                {
                    readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
                }
                string data = readStream.ReadToEnd();                
                LitForOtherWebsite.Text = data;
                response.Close();
                readStream.Close();
            }
        }




HTML Part:

<asp:Literal ID="LitForOtherWebsite" runat="server"></asp:Literal>


Please vote!!


Try:
const string virtualPath = "~/Contents/sample.html";
string physicalPath = Server.MapPath(virtualPath);
display_html.Text = System.IO.File.ReadAllText(physicalPath);


But do bear in mind the comment from F-ES Sitecore: if the file you're loading is a complete document, rather than an HTML fragment, then you're going to run into issues.

If you just want to remove the borders from the iframe, you can do that:

<style>
iframe.seamless {
    background-color: transparent;
    border: 0px none transparent;
    padding: 0px;
    overflow: hidden;
}
</style>

<iframe class="seamless" frameborder="0" allowtransparency="true" scrolling="no" src="Contents/sample.html"></iframe>


HTML5 iFrame Seamless Attribute - Stack Overflow[^]