Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net Win Server 2003,图像和ASHX问题_Asp.net_Vb.net_Image_Ashx - Fatal编程技术网

Asp.net Win Server 2003,图像和ASHX问题

Asp.net Win Server 2003,图像和ASHX问题,asp.net,vb.net,image,ashx,Asp.net,Vb.net,Image,Ashx,我的ASP.Net应用程序在IIS6(Windows Server 2003)中运行时出现问题,但在IIS7(Windows Server 2008R2)中运行时却完美无缺。我正在使用ASHX调整图像大小,然后在另一个winform(DisplayImage.aspx)上的ASP:Image控件中显示结果。当我在IIS7中运行应用程序时,它会在ASP:image控件中完美地显示图像,但当我在IIS6中运行应用程序时,图像不会显示。我没有收到关于IIS6框的任何错误,只是带有红色X的谚语框。以下是

我的ASP.Net应用程序在IIS6(Windows Server 2003)中运行时出现问题,但在IIS7(Windows Server 2008R2)中运行时却完美无缺。我正在使用ASHX调整图像大小,然后在另一个winform(DisplayImage.aspx)上的ASP:Image控件中显示结果。当我在IIS7中运行应用程序时,它会在ASP:image控件中完美地显示图像,但当我在IIS6中运行应用程序时,图像不会显示。我没有收到关于IIS6框的任何错误,只是带有红色X的谚语框。以下是我的代码:

以下是显示图像aspx WinForm中的代码:

受保护的子页加载(ByVal sender作为对象,ByVal e作为System.EventArgs)处理Me.Load

If Not IsPostBack Then
    ''Code to retrieve filename here
    With Image1
        .ImageUrl = "~/ImageHandler.ashx?imageName=" & filePath 
    End With
End If
端接头

以下是DisplayImage.aspx中的HTML/ASP.Net代码

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="DisplayImage.aspx.vb" Inherits="Mobile.DisplayImage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

    <head id="Head1" runat="server">
        <meta content="index,follow" name="robots" />
        <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type" />
        <meta content="minimum-scale=1.0, width=device-width, maximum-scale=0.6667, user-scalable=no" name="viewport" />

        <meta name="HandheldFriendly" content="true" />
        <meta name="viewport" content="width=device-width" />

        <link href="../css/style.css" rel="stylesheet" type="text/css" />

        <script src="../scripts/functions.js" type="text/javascript"></script>

        <title>CrimeNtel</title>
    </head>
    <body>
        <form id="theform" runat="server">
            <div id="topbar">
                <div id="leftnav">
                    <a href="Default.aspx"><img alt="home" src="../images/home.png" /></a><a id="goback" runat="server">Return</a>
                </div>
                <div>
                    Image Viewer
                </div>
            </div>
            <div>
                <fieldset>
                    <span>
                        <div id="titleHeader" runat="server" style="text-align:center">Linked Image</div>
                    </span>

                    <div style="text-align:center" style="text-align:center">
                        <asp:Image ID="Image1" runat="server" />
                    </div>
                </fieldset>
            </div>
        </form> 
    </body>
</html>

克里门特尔
返回
图像查看器
链接图像
以下是ImageHandler.ashx中的代码:

Imports System.Web
Imports System.Web.Services
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Imports System.Web.Mobile
Imports System.IO

Public Class ImageHandler
    Implements System.Web.IHttpHandler


    Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        Dim fileName As String = HttpContext.Current.Request("imagename")
        Dim screenHeight As Integer = 300
        Dim screenWidth As Integer  = 300
        Dim fileExtension As String = Path.GetExtension(fileName).Replace(".", "").ToUpper

        Select Case fileExtension.ToUpper
            Case "JPG"
                context.Response.ContentType = "image/jpg"
            Case "PNG"
                context.Response.ContentType = "image/png"
            Case "BMP"
                context.Response.ContentType = "image/bmp"
            Case "GIF"
                context.Response.ContentType = "image/GIF"
            Case Else
                context.Response.ContentType = "image/jpg"
        End Select

    ''Loads Virtual Directory  from Web Config File
       ''Note Virtual Directory is located in the Root of the Default Web Site
        Dim _virtualDirectory As String = ConfigurationManager.AppSettings("VirtualDirectory")

        Try
        Dim bmp As Bitmap = New Bitmap((_virtualDirectory & fileName.Trim)

                Dim img As System.Drawing.Image = FixedSize(bmp, screenWidth, screenHeight)
                img.Save(_virtualDirectory & "/Thumbs/displayedImage." & fileExtension)
                img.Dispose()
                context.Response.WriteFile(_virtualDirectory & "/Thumbs/displayedImage." & fileExtension)

        Catch ex As Exception
            'context.Response.Write("<script>alert('" & ex.Message & "');</script>")
        End Try
    End Sub

    Private Shared Function FixedSize(imgPhoto As Image, Width As Integer, Height As Integer) As Image
        ''Found code at 
        ''http://www.codeproject.com/KB/GDI-plus/imageresize.aspx

        Dim sourceWidth As Integer = imgPhoto.Width
        Dim sourceHeight As Integer = imgPhoto.Height
        Dim sourceX As Integer = 0
        Dim sourceY As Integer = 0
        Dim destX As Integer = 0
        Dim destY As Integer = 0

        Dim nPercent As Single = 0
        Dim nPercentW As Single = 0
        Dim nPercentH As Single = 0

        nPercentW = (CSng(Width) / CSng(sourceWidth))
        nPercentH = (CSng(Height) / CSng(sourceHeight))

        If nPercentH < nPercentW Then
            nPercent = nPercentH
            destX = System.Convert.ToInt16((Width - (sourceWidth * nPercent)) / 2)
        Else
            nPercent = nPercentW
            destY = System.Convert.ToInt16((Height - (sourceHeight * nPercent)) / 2)
        End If

        Dim destWidth As Integer = CInt(Math.Truncate(sourceWidth * nPercent))
        Dim destHeight As Integer = CInt(Math.Truncate(sourceHeight * nPercent))

        Dim bmPhoto As New Bitmap(Width, Height, PixelFormat.Format24bppRgb)
        bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution)

        Dim grPhoto As Graphics = Graphics.FromImage(bmPhoto)
        grPhoto.Clear(System.Drawing.ColorTranslator.FromHtml("#C5CCD4"))  'Color.DarkGray) ' Color.White)
        grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic

        grPhoto.DrawImage(imgPhoto, New Rectangle(destX, destY, destWidth, destHeight), New Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel)

        grPhoto.Dispose()
        Return bmPhoto
    End Function

    ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property
End Class
导入系统.Web
导入System.Web.Services
导入系统。绘图
导入System.Drawing.Drawing2D
导入System.Drawing.Imaging
导入System.Web.Mobile
导入System.IO
公共类ImageHandler
实现System.Web.IHttpHandler
子ProcessRequest(ByVal上下文作为HttpContext)实现IHttpHandler.ProcessRequest
Dim文件名为String=HttpContext.Current.Request(“imagename”)
尺寸屏幕高度为整数=300
尺寸屏幕宽度为整数=300
Dim fileExtension As String=Path.GetExtension(fileName).Replace(“.”,“”)。ToUpper
选择Case fileExtension.ToUpper
案件“JPG”
context.Response.ContentType=“image/jpg”
案例“PNG”
context.Response.ContentType=“image/png”
案例“BMP”
context.Response.ContentType=“image/bmp”
案例“GIF”
context.Response.ContentType=“image/GIF”
其他情况
context.Response.ContentType=“image/jpg”
结束选择
''从Web配置文件加载虚拟目录
''注意虚拟目录位于默认网站的根目录中
Dim _virtualdirectoryas String=ConfigurationManager.AppSettings(“virtualDirectory”)
尝试
将bmp调整为位图=新位图(_virtualDirectory&fileName.Trim)
Dim img As System.Drawing.Image=固定大小(bmp、屏幕宽度、屏幕高度)
img.Save(_virtualDirectory&“/Thumbs/displayedImage.”和文件扩展名)
img.Dispose()
context.Response.WriteFile(_virtualDirectory&“/Thumbs/displayedImage.”和文件扩展名)
特例
'context.Response.Write(“警报('”&ex.Message&“);”)
结束尝试
端接头
私有共享函数FixedSize(imgPhoto作为图像,宽度作为整数,高度作为整数)作为图像
''在找到代码
''http://www.codeproject.com/KB/GDI-plus/imageresize.aspx
Dim sourceWidth为整数=imgPhoto.Width
Dim sourceHeight作为整数=imgPhoto.Height
Dim sourceX为整数=0
Dim sourceY作为整数=0
Dim destX为整数=0
Dim destY为整数=0
单个尺寸百分比=0
尺寸nPercentW为单个=0
尺寸nPercentH为单个=0
nPercentW=(CSng(宽度)/CSng(源宽度))
nPercentH=(CSng(高度)/CSng(源高度))
如果nPercentH
解决方案 问题是,该网站是在正确的信誉下运行的,但我必须将以下代码行添加到我的Web配置文件中,以便我的应用程序模拟有权访问这些文件的用户:

<system.web>
    <!--This will allow website to run under a different account than that of ASP.Net
      <identity impersonate="true" userName="DomainName\UserName" password="p@5sW0Rd"/>
</system.web>


我认为这是一个许可问题。您需要授予网络服务访问包含映像的文件夹的权限。

打开IIS 6日志。将其设置为记录所有内容。然后查看记录的请求,看看它在做什么。您是正确的,即使我在应用程序中设置了AD用户帐户,我仍然需要将添加到web配置文件中。