如何在 ASP.Net 中制作可嵌入代码
您一定见过像代码这样的小部件,人们将其放入 HTML 中,然后它开始在其中显示一个小部件,我们如何在 ASP.net 中做到这一点,例如,如果我想向任何地方显示我网站的某些特定数据放置了特定的代码,我如何生成可嵌入的代码,可以开始向任何站点的任何地方显示我的特定数据块?
you must have seen widgets like code which people place inside their HTML and it starts showing a small widget in there, how we can we do it in ASP.net, for example if i want to show some specific data of my site to anywhere some specific code is placed, how can i generate that embeddable code that can start showing my specific block of data to anywhere from any site?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是不同的人使用的几种在外部网站上嵌入内容片段的方法。
1) 一个 iframe!
iframe 可能是一个古老的害虫,但非常擅长显示一些外部内容。它们已被重新添加到 HTML 5 草案规范中的 HTML 标准中,因此您将来应该会获得对它们的面向未来的支持。
您可以设置 iframe 的样式(指定宽度和高度)以及所有这些爵士乐。
2) 外部图像
这主要由广告引擎使用。您在页面上弹出一个图像,该图像会动态创建以显示一些广告 - 每次出现时都不同。如果您希望信息在屏幕上可读(即可访问),那么这不太好。
3) 服务器端 API
您可以提供一个 API,以便人们可以调用您网站上的“服务”,为他们提供小部件的信息。例如,他们的 ASP.NET 代码或 PHP 代码(或任何语言)调用 http:// www.widget-address.com/Widgets/WidgetService/ 并返回一些可以格式化并显示在页面上的数据。这将为您带来内联 HTML 的好处,这是显示数据的最容易访问且最有效的方式。
还有很多其他方法,所以如果您不喜欢其中一种,我相信更多的建议将会涌入 - 包括(小心......)JavaScript / AJAX。
Here are a few methods used by various people to embed a snippet of content on an external website.
1) An iframe!
iframe's can be a right old pest, but are quite good at displaying a bit of external content. They have been added back into the HTML standards in the HTML 5 draft specification, so you should get futureproof support for them in the future.
You can style your iframe (give it a width and height) and all that jazz.
2) External Image
This is largely used by advertising engines. You pop an image on the page and the image is dynamically created to display some advert - each time it appears it is different. This isn't great if you want information to be screen-readable (i.e. accessible).
3) Server Side API
You could make an API available so people can call a "service" on your site that supplies them with the information for the widget. For example, their ASP.NET code or PHP code (or whatever language) calls http://www.widget-address.com/Widgets/WidgetService/ and it returns some data that they can format and display on their page. This would give you the benefit of inline HTML, which is the most accessible and valid way of displaying the data.
There are lots of other methods, so if you don't fancy one of these, I'm sure more suggestions will flood in - including (be careful...) JavaScript / AJAX.
我不太确定我理解这个问题,所以如果我离这里很抱歉。但我猜你正在使用 asp.net 的 webforms 框架?如果您有的话,有一个名为服务器控件的东西。这些可用于创建小部件,例如日历(已包含在框架中,因此无需再次构建)。
如果你正在寻找代码块,类似于 php 中的
(如果你使用过的话),那么答案是
<% % >
。这些是 .net 世界中的代码块。如果你想写一些东西,你可以在代码块中使用 Response.Write("string to write"); 。或者您可以使用更快的方法:<%="string to write"%>
这将呈现相同的 think (string to write)。如果您使用 Webforms 框架,您还可以利用框架中内置的服务器控件。您可以在此处阅读有关该框架的更多信息,或者直接谷歌 asp.net网络表格。
I'm not quite sure I understand the question, so I'm sorry if I'm way off here. But I guess you are using the webforms framework for asp.net? If you are there is something called server controls. Those can be used to create widgets like calenders for example (that is already included in the framework, so no need to build it again).
If you are looking for code block, similar to
<?php [[code]] ?>
in php (if you have used that), then the answer is<% %>
. Those are code blocks in the .net world. If you want to write something out you useResponse.Write("string to write");
inside the code block. Or you can use the faster way:<%="string to write"%>
that will render the same think (string to write).If you are using the webforms framework you can also take advantage of the built in server controls in the framework. You can read more about the framework here or simply google asp.net webforms.