|
and that is what I was kind of thinking. The way I am using the handler for images is that I point an image control's navigate URL to the handler ("www.mysite.com/ShowImage.ashx?ID=23"), which I can also use as a link for an image and pull up just fine as well. I couldn't find any good tutorials on the net that explained how docs were downloaded, just how they were uploaded. thanks.
|
|
|
|
|
So I tried implementing the same logic used to get images from the database, but instead of displaying the file my browser wants to open a file called DisplayResume.ashx.
Here is the code I used in my event Handler:
<%@ WebHandler Language="VB" Class="displayResume" %>
Imports System
Imports System.Web
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports util
Public Class displayResume : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim appID As Integer
Dim mimeType As String
If Not context.Request.QueryString("ID") Is Nothing Then
'place ID in the the appID variable
appID = context.Request.QueryString("ID").ToString
'get the mimetype for the file from table
mimeType = getMimeType(appID.ToString)
If Not mimeType Is Nothing Then
context.Response.ContentType = mimeType
Dim strm As Stream = getResume(appID)
Dim buffer As Byte() = New Byte(4095) {}
Dim byteSeq As Integer = strm.Read(buffer, 0, 4096)
Do While byteSeq > 0
context.Response.OutputStream.Write(buffer, 0, byteSeq)
byteSeq = strm.Read(buffer, 0, 4096)
Loop
Else
Throw New ArgumentException("Can't retrieve MIME Type")
End If
Else
Throw New ArgumentException("No Parameter specified")
End If
End Sub
''' <summary>
''' Gets the mime type for the resume from the database
''' </summary>
''' <param name="appID">appID for the resume we are looking for</param>
''' <returns>mimetype string</returns>
''' <remarks></remarks>
Public Function getMimeType(ByVal appID As String) As String
Dim rdrMime As SqlDataReader = GetReader("select mimeType from resumes where appID =" & appID)
Dim mimetype As String = Nothing
Try
While rdrMime.Read
mimetype = rdrMime("mimeType").ToString
End While
Catch ex As Exception
Return Nothing
Finally
rdrMime.Close()
End Try
Return mimetype
End Function
''' <summary>
''' gets the binary format of the file from the database
''' </summary>
''' <param name="ID">appID that is pointing to the resume file</param>
''' <returns>binary representation of the resume file</returns>
''' <remarks></remarks>
Public Function getResume(ByVal ID As Integer) As Stream
Dim strConnection As String = ConfigurationManager.ConnectionStrings("connectionString").ToString
Dim conn As SqlConnection = New SqlConnection(strConnection)
Dim sql As String = "Select theFile from Resumes where appID = " & ID
Dim cmd As SqlCommand = New SqlCommand(sql, conn)
Try
conn.Open()
Dim file As Object = cmd.ExecuteScalar
Return New MemoryStream(CType(file, Byte()))
Catch ex As Exception
Return Nothing
Finally
conn.Close()
conn.Dispose()
End Try
End Function
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
|
|
|
|
|
Did you add the required settings in the web.config file?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
What setting would that be? I never have made any changes for displaying images before.
|
|
|
|
|
I'm sorry, you were writing and http handler, I thought you knew you need to add it the web.config file also.
http://support.microsoft.com/kb/308001[^]
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Okay. I've never had to do that with my images, so i guess I never knew to add anything to the web config. I'm still confused as to what I need to set the path and type to in the add section under httpHandlers.
|
|
|
|
|
How to Protect XML from outside access in asp.net.
I have use
<configuration>
<location path="Login.xml">
<system.web>
<authorization>
<deny users="*"/>
</authorization>
</system.web>
</location>
</configuration>
But it doesn`t work online.
|
|
|
|
|
I'm pretty sure that's a setting you should be setting on the folder containing the XML file on the web server. Alternatively, you can embed the XML file in your application's DLL, which will make it inaccessible to the client side. Or you could store it in a database.
|
|
|
|
|
I have xml in root folder. I just want to stop viewing xml file from outside.
|
|
|
|
|
Hi All,
I developed a login page and added a link button(for logout) in all other pages. The code that I used behind logout is just Response.Redirect("Login.aspx")
So, when I click logout, it redirects me to the Login page but when I click back button in the browser, it goes into the application without the need of login.
Can anyone please help me how to do a safe logout in a web appliction so that even when I click back button it should not be entered into the application again without a proper login?
i've neither used a session variable nor FormsAuthentication. If I have to use session variables, please explain me how to use them(as I'm new to .NET). The code that I used in the login page is below:
Imports System.Data.SqlClient<br />
<br />
Partial Class Login<br />
Inherits System.Web.UI.Page<br />
Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate<br />
Dim authentication As Boolean = False<br />
authentication = Sitelevelauthentication(Login1.UserName, Login1.Password)<br />
e.Authenticated = authentication<br />
If authentication = True Then<br />
Response.Redirect("Default.aspx")<br />
End If<br />
<br />
End Sub<br />
Private Function Sitelevelauthentication(ByVal Username As String, ByVal Password As String) As Boolean<br />
Dim boolretval As Boolean<br />
Dim con As New SqlConnection<br />
Dim Dr As SqlDataReader<br />
Dim sql As String<br />
con.ConnectionString = "Data Source=;Initial Catalog=;User ID=;Password="<br />
sql = "SELECT * FROM Login"<br />
con.Open()<br />
Dim cmd As New SqlCommand(sql, con)<br />
Dr = cmd.ExecuteReader()<br />
While Dr.Read()<br />
If Username = Dr("Username").ToString And Password = Dr("Password") Then<br />
boolretval = True<br />
End If<br />
Dr.Close()<br />
Return boolretval<br />
<br />
End While<br />
End Function<br />
End Class
Thank you,
Ranjani.
|
|
|
|
|
|
|
Hi All,
I have .cmd file which has an environment variable steps. This .cmd file is giving wrong results. When I edit and saw the .cmd file its setting the steps evn variable twice. Is it because of this the wrong results are coming.
Whats the meaning of setting the env variables twice, does it give different meaning than setting it for only once. And whats the impact of setting the environment variables twice.
set steps=%steps% "_07.5.2 QUTransUnionSimulator"
set steps=%steps% "_07.5.1 RunScoreBureauSimulator"
set steps=%steps% "_07.5.2 QUTransUnionSimulator"
set steps=%steps% "_07.5.1 RunScoreBureauSimulator"
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
I doubt you'll get an answer in the Asp.Net forum for a .cmd question. Try posting in the right place: perhaps the System Admin forum.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
Ok. Sure. Thanks.
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
My page currently displays the five most recent feeds off a site. However I would like to try and filter the feeds based on keywords that are in the description field. My code right now for downloading the feed and binding it to a repeater is:
Dim rssHUDPressDoc As XDocument = XDocument.Load("http://www.hud.gov/news/hudrss.xml")
Dim pressPosts = From item In rssHUDPressDoc.Descendants("item") _
Take 5 _
Select Title = item.Element("title").Value, _
link = item.Element("link").Value, _
description = item.Element("description").Value, _
pubDate = item.Element("pubDate").Value
If pressPosts.Count = 0 Then
lblNoPress.Visible = True
Else
rssHUDPress.DataSource = pressPosts
rssHUDPress.DataBind()
End If
The above code returns the feeds just fine and I'm able to display it with no problem. However I'm trying to do something to the effect that if I have a string array of keywords:
Dim keywords() as string = new string(){"keyword1","keyword2","keyword3"}
I can change the LINQ statement to something like this:
Dim pressPosts = From item In rssHUDPressDoc.Descendants("item") _
Take 5 _
Where item.Element("description").Value.ToString.Contains(keywords)
Select Title = item.Element("title").Value, _
link = item.Element("link").Value, _
description = item.Element("description").Value, _
pubDate = item.Element("pubDate").Value
However the .Contains() method only accepts a single string, not an array. Currently I need to filter by multiple keywords that apply to our industry and I'm trying to avoid writing numerous OrElse statements within the Where clause. Any suggestions on how I can do this?
Thanks in advance for any help. Been working on this problem for two days now and I can't think of what else to try.
|
|
|
|
|
I have a normal ASP web app that navigates to a different content page when a menu clicked. As usual, this type of navigation is a normal function of menu control. My question is how do I call back to an EXE or VBScript file from a menu-item? Thanks.
Best,
Jun
modified on Friday, May 27, 2011 9:55 AM
|
|
|
|
|
See Here[^], it should help.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
Hi, I'm using ASP.NET administrative tool to configure security. I want to authenticate page-by-page not directory by directory
On the left side in (MANAGE ACCESS RULES), it only shows directories, not pages. How to select particular page and then authenticate in WAT. If not, then what is the alternative.
Regards
Asif Rehman
|
|
|
|
|
The one that I know of you can do it from web.config file. So in your web.config you need to use the location tag to exclude the pages that you do not want to authenticate..
Look at this example:
<configuration>
<location path="YourPath/yourfile.aspx">
<system.web>
<authorization>
<deny users="?" /> - OR - <allow users="?" />
</authorization>
</system.web>
</location>
</configuration>
|
|
|
|
|
I am maintaining an old vb.net app that is currently compiling and running in .net 1.1
the problem is we want to upgrade it to operate in 2.0 while still being able to compile and run in 1.1 as some clients will not want to upgrade. We would like to avoid having a separate code line for each version.
I am running into a problem with a modal page being popped up - on return to the main page this error is thrown when running 2.0:
"Exception : System.ArgumentException : Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation."
The 2 solutions they recommend are not available in 1.1. I have tried to import different @Page directives based on the version of dotnet to no avail.
Any advice is appreciated.
|
|
|
|
|
Make sure you place the enableeventvalidation to the right place in web.config. It should be inside system.web. For reference:
<configuration>
<appSettings>
</appSettings>
<system.web>
<pages validateRequest="false" enableEventValidation="false"/>
<customErrors mode="Off"/>
<compilation debug="true">
</compilation>
</system.web>
</configuration>
OR
1.1 event validation consisted of checking for "<"'s in the postback
data. You should use the page directive to turn it off.( i know you have already tried that)
Also check this link that might be helpful as well; Enable event validation[^]
|
|
|
|
|
is it possibled that a user should not be able to resize a perticular page in a web site? if yes then how...
just thinking if i can skipp writing 'onresize' event
Thanks
|
|
|
|
|
The resizing is controlled by the browser and there is no way to prevent a user from resizing the window, unless you are opening another window, such as a popup, and that can be blocked by settings so it is not a good practice.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
yaa i think so...
thanks mark...
|
|
|
|