是否可以使用ASP.NET的文字控件显示.html文件? [英] Is it possible to display .html file using literal control of ASP.NET?

查看:65
本文介绍了是否可以使用ASP.NET的文字控件显示.html文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用文字在我的网页上显示我的.html文件。说实话,我使用iframe使其工作,但我不打算使用iframe的唯一原因是每次加载我的.html文件时,iframe往往有滚动和边框和灰色背景。我以为我可以通过使用formborder或formBorder设置为0来修复它,滚动=非并将它的背景颜色设置为白色但不幸的是,它都没有工作。我想做的就是在我的网页上显示我的.html,没有这些边框,滚动和不变的背景颜色。我读了一些文章,我可以使用asp.net控件文字来显示我的.html文件但是所有这些文件都没有显示如何执行此过程的过程。



如果你能对我的问题提出一些建议或解决方案,我会很高兴和感激你。



干杯〜



注意:我的sample.html是从sample.rtf转换而来的文档。我以为我可以在我的页面上显示.html。



我尝试了什么:



在我的服务器上



注意:我想保留我的代码,因为我将很快用我的路径填充文字数据库,我希望我的字符串file_location在传递文字控件之前捕获它。



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





我的客户



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

解决方案

试试这个:



 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 =  < span class =code-string>〜/ 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 <温泉n class =code-keyword> 0px;
溢出 < span class =code-keyword> 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[^]


这篇关于是否可以使用ASP.NET的文字控件显示.html文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆