[英]ASP.NET SlideShowExtender retrieving images from web service, but doing nothing when executed
[英]Why are images not displaying when using the ajaxtoolkit:slideshowextender?
我正在嘗試根據在線提供的演示代碼實現“ajaxToolkit:SlideShowExtender”屬性,還嘗試了以下答案之一中發布的來自 GitHub 的代碼。
我嘗試過的事情:
從我的Test.aspx文件:
<%@ Page Title="Test" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit"%>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<table style="align-content:center; width:500px; height:250px;">
<tr style="align-content:center;">
<td>
<asp:Label ID="Label1" runat="server" ForeColor="#000000" />
</td>
</tr>
<tr style="align-content:center;">
<td>
<asp:Image runat="server" ID="Image1" Height="250" Width="400" />
</td>
</tr>
<tr style="text-align:center;">
<td>
<asp:ImageButton ID="ImgBtnPrevious" runat="server" ImageUrl="~/images/Buttons/back.png"/>
</td>
<td>
<asp:Button ID="BtnPlayStop" runat="server" BackColor="Black" ForeColor="White"/>
</td>
<td>
<asp:ImageButton ID="ImgBtnNext" runat="server" ImageUrl="~/images/Buttons/forward.png"/>
</td>
</tr>
</table>
<ajaxToolkit:SlideShowExtender ID="SlideShowExtender1" runat="server"
AutoPlay="true" ImageTitleLabelID="Label1" PlayInterval="2000" Loop="true" PlayButtonID="BtnPlayStop"
PlayButtonText="Play" StopButtonText="Stop" PreviousButtonID="ImgBtnPrevious" NextButtonID="ImgBtnNext"
SlideShowAnimationType="SlideRight" TargetControlID="Image1" SlideShowServiceMethod="GetSlides" />
</asp:Content>
(我的圖像按鈕顯示正常)
我后面的代碼( Test.aspx.cs文件):
如您所見,我嘗試了三種不同的圖像顯示方式。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
using System.IO;
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public AjaxControlToolkit.Slide[] GetSlides()
{
/*
List<Slide> slides = new List<Slide>();
string myimgdir = HttpContext.Current.Server.MapPath("~/images/Test/");
DirectoryInfo dir = new DirectoryInfo(myimgdir);
var myslides = from displayimg in dir.GetFiles()
select new Slide
{
Name = displayimg.Name,
ImagePath = "~/images/Test/" + displayimg.Name
};
return myslides.ToArray();*/
/*
string[] imagenames = System.IO.Directory.GetFiles(Server.MapPath("~/images/Test/"));
AjaxControlToolkit.Slide[] photos = new AjaxControlToolkit.Slide[imagenames.Length];
for (int i = 0; i < imagenames.Length; i++)
{
string[] file = imagenames[i].Split('\\');
photos[i] = new AjaxControlToolkit.Slide("Images/" + file[file.Length - 1], file[file.Length - 1], "");
}
return photos;
*/
AjaxControlToolkit.Slide[] slides = new AjaxControlToolkit.Slide[4];
slides[0] = new AjaxControlToolkit.Slide("~/images/Test/ME1.png", "First image of my album", "First Image");
slides[1] = new AjaxControlToolkit.Slide("~/images/Test/ME2.png", "Second image of my album", "Second Image");
slides[2] = new AjaxControlToolkit.Slide("~/images/Test/ME3.png", "Third image of my album", "Third Image");
slides[3] = new AjaxControlToolkit.Slide("~/images/Test/ME4.png", "Fourth image of my album", "Fourth Image");
return (slides);
}
}
我的 Web.config(因為它還包含與 Ajax 控件相關的代碼):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="ajaxControlToolkit" type="AjaxControlToolkit.AjaxControlToolkitConfigSection, AjaxControlToolkit" requirePermission="false" />
</configSections>
<ajaxControlToolkit useStaticResources="true" renderStyleLinks="false" htmlSanitizer="AjaxControlToolkit.HtmlEditor.Sanitizer.DefaultHtmlSanitizer, AjaxControlToolkit.HtmlEditor.Sanitizer" tempFolder="~/Temp" />
<location path="Temp">
<system.webServer>
<handlers>
<clear />
</handlers>
<modules>
<clear />
</modules>
</system.webServer>
</location>
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5.2">
<assemblies>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<httpRuntime targetFramework="4.5.1" />
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<namespaces>
<add namespace="System.Web.Optimization" />
<add namespace="Microsoft.AspNet.Identity" />
</namespaces>
<controls>
<add assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagPrefix="ajaxToolkit" />
<add namespace="InfoBlock" tagPrefix="samples" />
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
</controls>
</pages>
<membership>
<providers>
<clear />
</providers>
</membership>
<profile>
<providers>
<clear />
</providers>
</profile>
<roleManager>
<providers>
<clear />
</providers>
</roleManager>
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
</providers>
</sessionState>
<customErrors mode="Off" />
<trust level="Full" />
</system.web>
<system.webServer>
<handlers>
<add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit" />
</handlers>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
<modules>
<remove name="FormsAuthentication" />
</modules>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.OAuth" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" culture="neutral" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="AjaxControlToolkit" publicKeyToken="28f01b0e84b6d53e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-18.1.1.0" newVersion="18.1.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.codedom>
</system.codedom>
</configuration>
嘗試通過 F12 > 網絡進行調試時,我看到以下內容(我不明白):
附注。 我在本地主機上運行它。
聚苯乙烯。 我正在運行 Visual Studio 2017 版本 15.2 (26430.16) 和 Microsoft .NET Framework 版本 4.7.03056。 (目標框架 .NET = 4.5.2)
我非常希望看到網頁滑塊中顯示的圖像。 感謝所有幫助!
在試驗瀏覽器中內置的網絡調試器時,我注意到以下內容(下面的屏幕截圖)。 似乎我的某些圖像子文件夾(如“測試”)丟失了。 這將解釋為什么找不到我的圖像。 知道這可能是什么原因嗎?
一個奇怪的事情是調試器顯示了slideShowServicePath
而它沒有在我的 .aspx 文件中配置。
瀏覽到https://localhost:44367/images/Test/ 時出現錯誤:
HTTP 錯誤 403.14 - Forbidden Web 服務器配置為不列出此目錄的內容。
將<directoryBrowse enabled="true" />
到 Web.config 后,我可以通過瀏覽器看到文件夾和其中的圖像(圖像鏈接,而不是實際圖片)。 然后我可以單擊並查看圖像。
但是我仍然看不到 Ajax SlideShowExtender 中的圖像。
您正在尋找的代碼適用於 Vs 2005 和 .net 2.0。 最新的工作代碼在這里。 問:ScriptManager 可能缺少某些內容或錯誤,它在我的“Site.master”頁面上配置,我無法將其添加到 aspx 頁面,因為它只能包含一個 ScriptManager。 **
A. 您必須將項目升級到 .net 4.0,然后還要更改 web.config。
**
https://github.com/DevExpress/AjaxControlToolkit/tree/master/AjaxControlToolkit.SampleSite/SlideShow
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<section name="ajaxControlToolkit" type="AjaxControlToolkit.AjaxControlToolkitConfigSection, AjaxControlToolkit" requirePermission="false"/>
</configSections>
<ajaxControlToolkit useStaticResources="true" renderStyleLinks="false" htmlSanitizer="AjaxControlToolkit.HtmlEditor.Sanitizer.DefaultHtmlSanitizer, AjaxControlToolkit.HtmlEditor.Sanitizer" tempFolder="~/Temp"/>
<location path="Temp">
<system.webServer>
<handlers>
<clear/>
</handlers>
<modules>
<clear/>
</modules>
</system.webServer>
</location>
<!--
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.
The following attributes can be set on the <httpRuntime> tag.
<system.Web>
<httpRuntime targetFramework="4.7" />
</system.Web>
-->
<system.web>
<compilation debug="true" targetFramework="4.7"/>
<machineKey validation="SHA1" decryptionKey="7EE421F6987EAFF4998E0F2ED5544AF1B931C82A1602BC2E" validationKey="5278D83EDD8E36C27E019D3E975D62A3FDF0E8EF50DB69F659D03EB18A4459D2B3271AA075173012EF122E2B7BFA49CDE16CC0DCC68F3E862E1EEE491D300DC9"/>
<siteMap>
<providers>
<add name="SamplesSiteMap" type="System.Web.XmlSiteMapProvider" siteMapFile="~/Samples.sitemap"/>
</providers>
</siteMap>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<controls>
<add assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagPrefix="ajaxToolkit"/>
<add namespace="InfoBlock" tagPrefix="samples"/>
</controls>
</pages>
<trust level="Medium"/>
</system.web>
<system.webServer>
<handlers>
<add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit"/>
</handlers>
</system.webServer>
<runtime>
</runtime>
</configuration>
我今天看到你的問題...
您已經在您的項目中添加了文件夾名稱“圖像” ... 多個圖像...根據您的喜好...
在 .aspx 頁面中添加 ajax 工具包參考....
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
.aspx 頁面代碼.....
<html>
<head runat="server">
<title></title>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</cc1:ToolkitScriptManager>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:Button ID="btnPrevious" runat="server" Text="<<" Font-Size="20" />
</td>
<td>
<asp:Image ID="Image1" runat="server" Height="300" Width="300" />
<cc1:SlideShowExtender ID="SlideShowExtender" runat="server" TargetControlID="Image1"
SlideShowServiceMethod="GetImages" ImageTitleLabelID="lblImageTitle" ImageDescriptionLabelID="lblImageDescription"
AutoPlay="true" Loop="true" PlayButtonID="btnPlay" StopButtonText="Stop"
PlayButtonText="Play" NextButtonID="btnNext" PreviousButtonID="btnPrevious">
</cc1:SlideShowExtender>
</td>
<td>
<asp:Button ID="btnNext" runat="server" Text=">>" Font-Size="20" />
</td>
</tr>
<tr>
<td colspan="3" align="center">
<asp:Button ID="btnPlay" runat="server" Text="Play" Font-Size="20" />
</td>
</tr>
<tr>
<td colspan="3" align="center">
<br />
<b>Name:</b>
<asp:Label ID="lblImageTitle" runat="server" Text="Label" /><br />
<b>Description:</b>
<asp:Label ID="lblImageDescription" runat="server" Text="Label" />
</td>
</tr>
</table>
</form>
</body>
.cs 頁面代碼...
using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using AjaxControlToolkit;
using System.Web.Services;
using System.Web.Script.Services;
using System.Collections.Generic;
public partial class CS : System.Web.UI.Page
{
[WebMethod]
[ScriptMethod]
public static Slide[] GetImages()
{
List<Slide> slides = new List<Slide>();
string path = HttpContext.Current.Server.MapPath("~/images/");
if (path.EndsWith("\\"))
{
path = path.Remove(path.Length - 1);
}
Uri pathUri = new Uri(path, UriKind.Absolute);
string[] files = Directory.GetFiles(path);
foreach (string file in files)
{
Uri filePathUri = new Uri(file, UriKind.Absolute);
slides.Add(new Slide
{
Name = Path.GetFileNameWithoutExtension(file),
Description = Path.GetFileNameWithoutExtension(file) + " Description.",
ImagePath = pathUri.MakeRelativeUri(filePathUri).ToString()
});
}
return slides.ToArray();
}
}
注意:-只需將此代碼以正確的方式放入您的項目中...這將起作用...我已經將此代碼用於我的項目.....我使用的是 3.5 版本...
看起來您缺少處理“ScriptResource.axd”請求的處理程序
<system.webServer>
<handlers>
<add name="ScriptResource" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" preCondition="integratedMode" />
</handlers>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.