代码不适用于域 [英] Code is not working on domain

查看:117
本文介绍了代码不适用于域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面显示的代码是我的应用程序的一部分....用于网站上的上传图像也将其存储在访问数据库中并显示在网页上.现在我的问题是....本地PC,但是当我在域上上传它时无法工作...我使用FileUpload控件来查找图像文件和一个按钮...名为Button1的按钮用于存储和上传文件....

The code shown below is the part of my application....for the upload images on website also store it in access database and shown it on webpage..Now my problem is....This code works fine on my local PC but couldn''t work when I upload it on domain...I used FileUpload control for find out image file and one button...named Button1 used for store and upload the file....

Imports System.Data.OleDb
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts

Partial Class _Default
    Inherits System.Web.UI.Page
    Dim c As New connection()
    Dim r As New Random()
    Dim sb As System.Text.StringBuilder

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            c.cmd = New OleDbCommand("select * from photos where username = 'nikul' ", c.cn)
            Call photos()
        Catch generatedExceptionName As NullReferenceException
            Response.Redirect("~/index.aspx")

        End Try
    End Sub

    Public Sub photos()
        If c.cn.State = Data.ConnectionState.Open Then c.cn.Close()
        c.cn.Open()
        c.dr = c.cmd.ExecuteReader()
        Dim table As New Table()
        Dim tr As New TableRow()
        Panel1.Controls.Add(table)
        Dim count As Integer = 0
        While c.dr.Read()
            If count = 2 Then
                tr = New TableRow()
                count = 0
            End If
            Dim tc As New TableCell()
            Dim image As New Image()
            image.ImageUrl = "~/photos/nikul/" & c.dr.GetValue(1).ToString()
            image.DescriptionUrl = "~/photos/nikul/" & c.dr.GetValue(1).ToString()
            image.Height = 200
            image.Width = 200
            tc.Controls.Add(image)
            tr.Controls.Add(tc)
            table.Controls.Add(tr)
            count += 1
        End While
        c.dr.Close()
    End Sub
  
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        If c.cn.State = Data.ConnectionState.Open Then c.cn.Close()
        c.cn.Open()
        If FileUpload1.HasFile Then
            Dim fi As New System.IO.FileInfo(FileUpload1.FileName.ToString())
            If fi.Extension.ToString() = ".jpg" Or fi.Extension.ToString() = ".png" Or fi.Extension.ToString() = ".bmp" Or fi.Extension.ToString() = ".gif" Or fi.Extension.ToString() = ".jpeg" Or fi.Extension.ToString() = ".JPEG" Or fi.Extension.ToString() = ".JPG" Or fi.Extension.ToString() = ".PNG" Or fi.Extension.ToString() = ".BMP" OrElse fi.Extension.ToString() = ".GIF" Then
                If System.IO.Directory.Exists(Server.MapPath("~/photos/nikul")) Then
                    Dim filename As String = r.[Next](9999).ToString()
                    FileUpload1.SaveAs(Server.MapPath("~/photos/nikul/" & filename))
                    c.cmd = New OleDbCommand("insert into photos values('nikul','" & filename & "')", c.cn)
                    c.cmd.ExecuteNonQuery()
                    Response.Redirect("~/index.aspx")
                Else
                    Dim filename As String = r.[Next](9999).ToString()
                    System.IO.Directory.CreateDirectory(Server.MapPath("~/photos/nikul"))
                    FileUpload1.SaveAs(Server.MapPath("~/photos/nikul/" & filename))
                    c.cmd = New OleDbCommand("insert into photos values('nikul','" & filename & "')", c.cn)
                    c.cmd.ExecuteNonQuery()
                    Response.Redirect("~/index.aspx")
                End If
            Else
                MsgBox("Upload Image file only......", MsgBoxStyle.Information, "Alert")
            End If
        Else
            MsgBox("Please select the file....", MsgBoxStyle.Information, "Alert")
        End If

    End Sub
End Class




我的域没有出现任何错误....但是我在网页上看不到图片...我的代码有任何问题吗?

通过此链接..... http://www.nayanarun.somee.com / [ ^ ]用于此项目预览....




I didn''t get any error on my domain....but i couldn''t see the image on my web page...is there any problem with my code???

Go through this link.....http://www.nayanarun.somee.com/[^] for this project preview....

推荐答案

您已检查域上文件夹的权限.需要检查的权限是针对用户的读写.如果没有,请给予许可并进行一次检查
Had you checked permissions for the folder on domain. Permission need to check is read and write for the user. If not Please give permission and check it once


不要将图像转换为文件格式....删除此行..

Don''t convert the image in file format....Remove this line..

Dim filename As String = r.[Next](9999).ToString()



并将filename替换为 FileUpload1.FileName.ToString()



and replace the filename with FileUpload1.FileName.ToString()


这篇关于代码不适用于域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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