Web service error forbiden

ManicCW

Well-known member
Joined
Jul 21, 2005
Messages
428
Location
Mostar
Programming Experience
Beginner
Hi,
i made small service that helps downloading file (force download). Now, my files are on one subdomain (with web service) and web app that gets files is on other subdomain.

Here is the service:

VB.NET:
[SIZE=2]<WebMethod()> _
[/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][SIZE=2] ForceDownload([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] FileName)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] FilePath [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = Server.MapPath("~/Data/Files/") & FileName
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] File.Exists(FilePath) [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] fs [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] FileStream
fs = File.Open(FilePath, FileMode.Open)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] bytBytes(fs.Length) [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Byte
[/COLOR][/SIZE][SIZE=2]fs.Read(bytBytes, 0, fs.Length)
fs.Close()
[/SIZE][SIZE=2][COLOR=#0000ff]Return[/COLOR][/SIZE][SIZE=2] bytBytes
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Function
[/COLOR][/SIZE]

and here is where i call it:

VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] FileName [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = e.Item.Cells(1).Text.Trim
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] fd [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DownloaderService.FileDownload
fd = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DownloaderService.FileDownload
Response.AddHeader("Content-Disposition", "attachment; filename=""" & FileName & """")
Response.ContentType = "application/octet-stream"
Response.BinaryWrite(fd.ForceDownload(FileName))
Response.End()
[/SIZE]

but whan i click grid button to download i get error:

The request failed with HTTP status 401: Access Denied.

Line 40: <System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/ManicCMS1/FileDownload/ForceDownload", RequestNamespace:="http://tempuri.org/ManicCMS1/FileDownload", ResponseNamespace:="http://tempuri.org/ManicCMS1/FileDownload", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)> _
Line 41: Public Function ForceDownload(ByVal FileName As Object) As Object
Line 42: Dim results() As Object = Me.Invoke("ForceDownload", New Object() {FileName})
Line 43: Return CType(results(0),Object)
Line 44: End Function

Can this be done this way? This is probably some security issue but i dont know the problem because bozh subdomains are members of the same domain.
 
Back
Top