首先建立其中一个Web窗体
注释:图片来源于images文件夹,没有可以自己建一个
<img src="images/小羊肖恩.jpg" width="300" height="200" />
<img src="images/小鸡不好惹.jpg" width="300" height="200" />
<img src="images/抹茶旦旦.jpg" width="300" height="200" />
效果如下:
接着建立第二个Web窗体,把第一个窗体的图片地址复制下来
注释:打开第一个窗体右键复制图片就行
如图:
然后用于第二个窗体,代码如下
以下图片来源于Index1<br/>
<img src="https://localhost:44339/images/%E5%B0%8F%E7%BE%8A%E8%82%96%E6%81%A9.jpg" width="300" height="200" />
<img src="https://localhost:44339/images/%E5%B0%8F%E9%B8%A1%E4%B8%8D%E5%A5%BD%E6%83%B9.jpg" width="300" height="200" />
<img src="https://localhost:44339/images/%E6%8A%B9%E8%8C%B6%E6%97%A6%E6%97%A6.jpg" width="300" height="200" />
效果如下:
然后在第一个Web窗体中添加一个Handler.ashx
建立好后要删除两行代码
再继续编写新的代码
public void ProcessRequest(HttpContext context)
{
Uri lastUrl = context.Request.UrlReferrer;
Uri currentUrl = context.Request.Url;
if (lastUrl.Host != currentUrl.Host || lastUrl.Port != currentUrl.Port)
{
string index = context.Request.PhysicalApplicationPath + "img/1.jpg";
context.Response.WriteFile(index);
}
else
{
context.Response.WriteFile(context.Request.PhysicalPath);
}
}
接着到第一个Web窗体的Web.config中编写最后的代码
刚开始是这样的,如图:
在中间添加以下代码
<system.webServer>
<handlers>
<add verb="*" path="images/*.jpg" type="WebSite.Handler1" name="plink"/>
</handlers>
</system.webServer>
然后可以看一下效果,如图:
今天的讲解结束,大家学会了没。