| Error: Must Declare Variable |
|
 |
Index ‹ Web Programming ‹ ASP.Net
|
- Previous
- 1
- 2
- ASP.Net >> HTTP Module attaching to Application_OnStartWe are creating an HTTP Module to add code to the Application On Start of an
applicaton. However, there is no HTTPApplication.OnStart event to attach to.
Does anyone know how to attach to this event? Oh, and while we are at it,
attach to the Session Start also.
Thanks,
--
Mike Logan
- 3
- 4
- 5
- Frontpage Client >> Explorer Information bar driving me nutsEvery time I "preview in a browser" the Explorer Information Bar pops up with
the "To help protect your Security, Internet Explorer has restricted this
file from showing active content that could access your computer" message.
I've tried to get rid of it by changing the myriad of custom settings under
the Security Tab of Internet Properties, but without results.
Using Front Page 2003 with XP pro.
Any help with this would bbe greatly appreciated!!
- 6
- ASP.Net >> When I click the cancel button of the DataGrid control, it raises DeleteCommand event!!! Why????????When I click the cancel button(EditCommandColumn) of the DataGrid control,
The DeleteCommand event is raised!!! Faint!!! Why this happend?? Why????????
Help help help help me, please!! Thanks!
The following code is my source code:
===========WebForm.aspx==================
<%@ Page Language="C#" AutoEventWireup="false" Debug="true" Trace="false"
Inherits="WebForm" Src="WebForm.aspx.cs" ContentType="text/html"
ResponseEncoding="gb2312" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Untitled Document</title>
<script language="javascript" type="text/javascript">
</script>
</head>
<body>
<Form Action="WebForm.aspx" Method="post" RunAt="server">
<asp:DataGrid
ID="myDG"
Width="100%"
BorderColor="#336699"
BorderWidth="1"
EnableViewState="false"
AutoGenerateColumns="false"
DataKeyField="CustomerID"
RunAt="server"
>
<HeaderStyle BackColor="#333366" ForeColor="#CCCCCC"
HorizontalAlign="center" Wrap="false" />
<ItemStyle BackColor="#993300" ForeColor="#FFFFFF" Wrap="false" />
<Columns>
<asp:EditCommandColumn
ButtonType="PushButton"
EditText="Edit"
UpdateText="Update"
CancelText="Cancel"
/>
<asp:ButtonColumn ButtonType="PushButton" CommandName="Delete"
Text="Delete" />
<asp:BoundColumn DataField="CustomerID" HeaderText="CustomerID"
ReadOnly="true" />
<asp:BoundColumn DataField="CompanyName" HeaderText="CompanyName" />
<asp:BoundColumn DataField="ContactName" HeaderText="ContactName" />
<asp:BoundColumn DataField="ContactTitle" HeaderText="ContactTitle" />
<asp:BoundColumn DataField="Address" HeaderText="Address" />
</Columns>
</asp:DataGrid><br>
<asp:Button ID="firstPage" Text="First" Enabled="false" CommandName="First"
RunAt="server" />
<asp:Button ID="prePage" Text="Previous" Enabled="false"
CommandName="Previous" RunAt="server" />
<asp:Button ID="nextPage" Text="Next" Enabled="false" CommandName="Next"
RunAt="server" />
<asp:Button ID="lastPage" Text="Last" Enabled="false" CommandName="Last"
RunAt="server" />
</Form>
<br>
<asp:Label ID="msgLbl" Text="" ForeColor="#FF0000" RunAt="server" />
</body>
</html>
=================WebForm.aspx.cs======================
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class WebForm : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button firstPage;
protected System.Web.UI.WebControls.Button prePage;
protected System.Web.UI.WebControls.Button nextPage;
protected System.Web.UI.WebControls.Button lastPage;
protected System.Web.UI.WebControls.Label msgLbl;
protected System.Web.UI.WebControls.DataGrid myDG;
protected System.Data.SqlClient.SqlConnection sqlConn;
protected System.Data.SqlClient.SqlCommand selectCmd;
protected System.Data.SqlClient.SqlDataAdapter sqlDA;
protected System.Data.DataSet myDS;
private System.Int32 _pageSize;
private System.Int32 _currentPage;
private System.Int32 _totalPages;
private System.Int32 _totalRecords;
private void Page_Load(Object sender, EventArgs e)
{
selectCmd.CommandText = "select count(CustomerID) from Customers";
sqlConn.Open();
_totalRecords =
(System.Int32)Math.Ceiling(Convert.ToDouble(selectCmd.ExecuteScalar()));
sqlConn.Close();
_totalPages = (System.Int32)Math.Ceiling((double)_totalRecords /
_pageSize);
ViewState["TotalRecords"] = _totalRecords;
ViewState["TotalPages"] = _totalPages;
if(IsPostBack == false && _totalPages > 0)
GetPagingData(null, new CommandEventArgs("First", null));
else if(IsPostBack == true)
BindGrid();
}
private void GetPagingData(Object sender, CommandEventArgs e)
{
switch(e.CommandName)
{
case "First":
_currentPage = 1;
selectCmd.CommandText = "select top " + _pageSize + " * from Customers "
+
"order by CustomerID";
break;
case "Previous":
_currentPage = ((System.Int32)ViewState["CurrentPage"]) - 1;
selectCmd.CommandText = "select top " + _pageSize + " * from Customers
where " +
"CustomerID < @CustomerID_First order by CustomerID desc";
selectCmd.Parameters["@CustomerID_First"].Value =
(String)ViewState["CustomerID_First"];
break;
case "Next":
_currentPage = ((System.Int32)ViewState["CurrentPage"]) + 1;
selectCmd.CommandText = "select top " + _pageSize + " * from Customers
where " +
"CustomerID > @CustomerID_Last order by CustomerID";
selectCmd.Parameters["@CustomerID_Last"].Value =
(String)ViewState["CustomerID_Last"];
break;
case "Last":
_currentPage = (System.Int32)ViewState["TotalPages"];
_pageSize = (int)ViewState["TotalRecords"] %
(int)ViewState["TotalPages"];
selectCmd.CommandText = "select top " + _pageSize + " * from Customers "
+
"order by CustomerID desc";
break;
}
if(IsPostBack == true)
myDS.Tables["Customers"].Rows.Clear();
sqlDA.Fill(myDS, "Customers");
if(e.CommandName == "Last" || e.CommandName == "Previous")
myDS.Tables["Customers"].DefaultView.Sort = "CustomerID";
myDG.DataSource = myDS.Tables["Customers"].DefaultView;
myDG.DataBind();
ViewState["CurrentPage"] = _currentPage;
ViewState["CustomerID_First"] = myDG.Items[0].Cells[2].Text;
ViewState["CustomerID_Last"] = myDG.Items[myDG.Items.Count -
1].Cells[2].Text;
_totalPages = (System.Int32)ViewState["TotalPages"];
if(_currentPage > 1 && _currentPage < _totalPages)
{
firstPage.Enabled = true;
prePage.Enabled = true;
nextPage.Enabled = true;
lastPage.Enabled = true;
}
else if(_currentPage == 1)
{
firstPage.Enabled = false;
prePage.Enabled = false;
nextPage.Enabled = true;
lastPage.Enabled = true;
}
else if(_currentPage == _totalPages)
{
firstPage.Enabled = true;
prePage.Enabled = true;
nextPage.Enabled = false;
lastPage.Enabled = false;
}
}
private void MyDG_Edit(Object sender, DataGridCommandEventArgs e)
{
myDG.EditItemIndex = e.Item.ItemIndex;
myDS.Tables["Customers"].Rows.Clear();
BindGrid();
}
private void MyDG_Update(Object sender, DataGridCommandEventArgs e)
{
}
private void MyDG_CancelEdit(Object sender, DataGridCommandEventArgs e)
{
myDG.EditItemIndex = -1;
myDS.Tables["Customers"].Rows.Clear();
msgLbl.Text = "CancelEdit.";
BindGrid();
}
private void MyDG_Delete(Object sender, DataGridCommandEventArgs e)
{
myDG.EditItemIndex = -1;
msgLbl.Text = "Delete.";
}
private void BindGrid()
{
selectCmd.CommandText = "select top " + _pageSize + " * from Customers " +
"where CustomerID >= @CustomerID_First";
selectCmd.Parameters["@CustomerID_First"].Value =
(String)ViewState["CustomerID_First"];
sqlDA.Fill(myDS, "Customers");
myDG.DataSource = myDS.Tables["Customers"].DefaultView;
myDG.DataBind();
}
override protected void OnInit(EventArgs e)
{
InitializeComponents();
base.OnInit(e);
}
private void InitializeComponents()
{
sqlConn = new SqlConnection("Server=(local);Database=Northwind;Integrated
Security=SSPI;" +
"Persist Security Info=false");
selectCmd = new SqlCommand();
selectCmd.Connection = sqlConn;
selectCmd.Parameters.Add("@customerID_First", SqlDbType.NChar, 5);
selectCmd.Parameters["@customerID_First"].Value = "";
selectCmd.Parameters.Add("@customerID_Last", SqlDbType.NChar, 5);
selectCmd.Parameters["@customerID_Last"].Value = "";
sqlDA = new SqlDataAdapter(selectCmd);
myDS = new DataSet();
_pageSize = 10;
_currentPage = 0;
_totalPages = 0;
_totalRecords = 0;
firstPage.Command += new CommandEventHandler(GetPagingData);
prePage.Command += new CommandEventHandler(GetPagingData);
nextPage.Command += new CommandEventHandler(GetPagingData);
lastPage.Command += new CommandEventHandler(GetPagingData);
myDG.EditCommand += new DataGridCommandEventHandler(MyDG_Edit);
myDG.UpdateCommand += new DataGridCommandEventHandler(MyDG_Update);
myDG.CancelCommand += new DataGridCommandEventHandler(MyDG_CancelEdit);
myDG.DeleteCommand += new DataGridCommandEventHandler(MyDG_Delete);
Load += new EventHandler(Page_Load);
}
}
- 7
- IIS >> IIS will not provide directly listing of drive mounted as folderI have mounted a disk drive as a folder under another disk. When I allow IIS to do a directly listing of the top level disk it works fine but when I try to go into the folder that is the mounted drive it fails and gives me the following error
The page cannot be foun
The page you are looking for might have been removed, had its name changed, or is temporarily unavailable. ..
Is there a way to allow drives mounted as folders to provide a directory listing under IIS
If so what are the configuration issues that I need to address
As a note, we have tried a variety of security, shared folders, mapped drives, etc. methods all to no avail
I would appreciate anyones help and feel free to email me directly
- 8
- ASP.Net >> <asp:Panels, borders and HTML tablesHi,
Is there any way to put a border round several rows in a standard HTML table
by surrounding them with an asp:Panel (or a client-side <div>)? When I try,
the border doesn't appear, though it does appear if I surround the entire
table with an asp:Panel.
E.g. this doesn't show the panel's border:
<table>
<asp:Panel ID=pnlPanel Runat=server BorderColor="Black"
BorderStyle="Solid" BorderWidth="2px">
<tr>
<td>Text</td>
<td>Text</td>
</tr>
<tr>
<td>Text</td>
<td>Text</td>
</tr>
</asp:Panel>
<tr>
<td>Text</td>
<td>Text</td>
</tr>
</table>
but this does:
<asp:Panel ID=pnlPanel Runat=server BorderColor="Black" BorderStyle="Solid"
BorderWidth="2px">
<table>
<tr>
<td>Text</td>
<td>Text</td>
</tr>
<tr>
<td>Text</td>
<td>Text</td>
</tr>
<tr>
<td>Text</td>
<td>Text</td>
</tr>
</table>
</asp:Panel>
- 9
- IIS >> Cookie and domain problemhi,
guys
my website is on server say servera.
i have a website on serverb
now servera and serverb are on different domians...
if serverb website creates a cookie on client pc with domain say
.xyz.com
now if try to read the cookie on client pc when servera website is run
i am unable
to access the cookie..
but if delpoy my website on the same domian from where the cookie was
created
i able to read the cookie...
so were is the problem lies is taht two web servers are on diff
domains that i am unable to read the cookie...
and if its then how to add servera to domain say .xyz.com what is the
process sholud go abt...
regds,
Navin Mahindroo
- 10
- 11
- ASP.Net >> Custom Errorhello all,
I am developing ASP.net application in VS.net - 2003.
On occurance of error i am trying to redirect it to the errorpage.htm in the
frame set. presently i am using the frame set with content, main, banner and
footer frames.
In content frame if the error occurs the errorpage.htm is opening in the
content page. But my requirement is to show the error page.htm in the parent
window.
how do i do this ??? what configuration i need to do in web.config? or is
any other possibilities??
Any help is highly appreciable.
regards
Chirag
- 12
- ASP.Net >> newbie question: connection string handlingHi
I wonder are there any "professional ways" to handle the connection string
if you like to deploy to various servers from one application, apart from
hard code in the application. e.g. read connection from txt, ini file, or
from registry.
if we use hard code in the application, then maintenance will be a problem
and need to change from server to server. but if we use registry to
customize the connection on the fly, would there be any performance or
security problems?
thanks
luke
- 13
- ASP.Net >> Late night beginners questionI'm reviewing the 70-305 course and I'm trying to do the Chapter 5 lab.
I've created the Calls.aspx page and the dsCalls xsd. I've set the
DataSource of dlstcalls to 'dsCalls.Tables(â??Callsâ??).DefaultView' as
instructed. (Page 296)
When I run the project and try to access the Calls page I get the error
message: BC30390: 'Chap5Lab.Calls.dsCalls' is not accessible in this context
because it is 'Private'.
What am I forgetting?
- 14
- ASP.Net >> DatabindingHi I am confused with databinding - i have created repeaters and gridviews
and i understand that <%# Eval("Price") %> returns the value of price thats
bound, and i even understand that i can do <%#
String.Format("0:f2",Eval("Price")) %> will format my values. What i cant
understand though is how to further format things like that... for example,
if i want to write a class to convert the price to another currency i thought
i could do something like this:
<&
String.Format("{0:f2}",EuroExchange.ConvertCurrency("GBP","EUR",Eval("Price")) %>
I get a message saying the name "EuroExchange" does not exist in this
context. Why is this? how could i make a class exist in that context?
Where can i find more information on this?
Regards
Owen
- 15
- Frontpage Client >> normal, html, and preview tabs gone??Hello all -
The strangest thing just happened - when I open my index.htm page I no
longer have the little tabs at the bottom left corner that say "normal",
"html", and "preview. The page opens in HTML and I can't see it in the
other two views at all. The rest of my open pages are fine.....
What did I do?
How do I get those little tabs back?
Thanks!
|
| Author |
Message |
GMorrison

|
Posted: Mon Jul 21 16:40:51 CDT 2003 |
Top |
ASP.Net >> Error: Must Declare Variable
I have the following code upon which I receive the error "Must declare the
variable '@job_id'".
--Begin Code --
OleDbConnection conDetail = new
OleDbConnection("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist
Security Info=False;Initial Catalog=ACRPPhilly;Data
Source=COMPUSA\\VSdotNET;Use Procedure for Prepare=1;Auto
Translate=True;Packet Size=4096;Workstation ID=COMPUSA;Use Encryption for
Data=False;Tag with column collation when possible=False");
OleDbDataAdapter datDetail = new OleDbDataAdapter();
OleDbCommand cmdDetail = new OleDbCommand("SELECT job_id, [Company Name],
[Position Title], [Position Contact Information], [Position Description],
discipline_id, City, state_id FROM dbo.jobs WHERE (job_id = @job_id)",
conDetail);
datDetail.SelectCommand = cmdDetail;
cmdDetail.Parameters.Add("@job_id", OleDbType.Integer, 10).Value =
Request["item"];
DataSet dsDetail = new DataSet();
datDetail.Fill(dsDetail);
-- End Code --
What am I doing wrong here?
Thanks,
Boris Zakharin
Web Programming190
|
| |
|
| |
 |
Boris

|
Posted: Mon Jul 21 16:40:51 CDT 2003 |
Top |
ASP.Net >> Error: Must Declare Variable
Yes, I tried hard-coding the value to zero, but the error is still reported.
> Boris,
>
> Are you sure Request["item"] is not null?
>
>
> Chris.
> -------------
> C.R. Timmons Consulting, Inc.
> http://www.crtimmonsinc.com/
|
| |
|
| |
 |
Boris

|
Posted: Mon Jul 21 20:04:58 CDT 2003 |
Top |
ASP.Net >> Error: Must Declare Variable
I got it to work by change to WHERE (job_id = ?). This is acceptable for my
interests, but I should be able to create named parameters, right? I'm using
MSDE to host the database.
|
| |
|
| |
 |
| |
 |
Index ‹ Web Programming ‹ ASP.Net |
- Next
- 1
- ASP.Net >> Why global themes are stored at 2 location in 2005.Hi all,
I have just using dot net studio 2005.
I am careating one theme. Here global themse are getting stored at 2
location.
\Microsoft.NET\Framework\<version>\ASP.NETClientFiles\Themes.
Inetpub\wwwroot\aspnet_client\system_web\<version>\Themes for IIS web
sites.
Why is it so?
thanks in advance.
- 2
- ASP.Net >> Server Control Deployment QuestionI created a server control (very simple) and am trying to move it to a common
server so that the other developers can add it to their visual studio
"toolbox" and start using it.
The problem that I am having is: If I use this dll (add it to the visual
studio toolbox) from the same computer it was compiled on - it works - If I
move the dll to a network share, THEN MOVE IT BACK - it fails. The error
message: The assembly <blah> could not be loaded. check that any dependencies
the file requres are installed.
Will I have to sign this assembly? Is that what this relates to?
Please help.
Craig
- 3
- IIS >> IIS TimeoutsWe are trying to download files from a system running Microsoft-IIS/6.0
using HTTP "GET" with the Inet ActiveX control.
The transfer if data appears to reset after an hour on different clients in
different cities using different transfer speeds.
Are there any server variables that set the transfer time for data transfer
with IIS? If so what are they and how are they changed?
- 4
- Frontpage Client >> Photo databaseWhat kind of database recomendations best used in FP without ASP, PHP,
alternatives? Can Access be used???
--
Thanks to all for your help! It's appreciated.
- 5
- ASP.Net >> Displaying table field in TextBox or Label controlsI started using VWD 2.0 Express Edition. I am new to web applications.
Can somebody post a sample code to show how to retrieve data from an
SQL 2005 table and display in a textbox or label?. I am not able to see
this in the documentation I came across, even though databinding grids
and some other controls is straight forward. Thanks.
- 6
- IIS >> CGI timeoutWith reference to the discussion:
http://groups.google.it/group/microsoft.public.inetserver.iis/browse_thread/thread/388cede3866fa874/ecda5b470cf372a0%23ecda5b470cf372a0?sa=X&oi=groupsr&start=1&num=3
it seems that although a different CGI timeout is set, IIS just ignores
it and use the default value 300s.
My question is "is there any method to overcome this bug, i mean using
the CGI with a different timeout?".
I need to raise timeout since debugging takes long time.
Thanks in advance.
--
Sephiroth
- 7
- 8
- ASP.Net >> Save XML from SQLI have a page that has javascript that relies on being able to read an XML
file. This XML file contains data that will be used to place markers on a
Google Map object.
The data in this file is held in a SQL 2005 database.
What Im unsure about is the most efficient way to get the data from my SQL
server and then saved as an XML file on the webserver.
I have create a stored procedure that returns the required data as xml
SELECT
addr_int_ID ID,
addr_txt_Lat Lat,
addr_txt_Lng Lng,
addr_int_Type "Type",
addr_txt_Tooltip Tooltip,
addr_txt_BubbleText BubbleText
from
GMarker
for xml auto
How do I dump this into a file in my web directory?
- 9
- ASP.Net >> Form validation doesn't workHi,
I have many, many forms that use all of the different form validation
controls. These work great on my local server however I have just been
alerted to the fact that the form validation doesn't work at all on
the web server causing all sorts of differing problems.
I would assume that it has something to do with the JavaScript for the
client side form validation however this is as far as I get.
Any suggestions / solutions?
Many thanks, Brett
- 10
- 11
- ASP.Net >> Ansi BSTR from dll, how to obtain in ASP.NETI'm currently using a wrapper which converts an ANSI BSTR from a dll.
(Yes, singlebyte but BSTR ! )
This works fine and i'm aware BSTR's returned must be destroyed by the
caller, which i do.
I noticed that ASP.NET's 'AS STRING' doesn't return the BSTR having
char(0)'s.
So i must assume ASP.NET does not destroy the BSTR + i need the real data.
What i want is a marshalAs but i'm not sure this is available for return
values.
Is it possible to rewrite this:
<DllImport("MY.DLL", EntryPoint:="GetStuff",
CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Ansi)> _
Private Shared Function __GetStuff(ByVal szHello As String) As Int32
End Function
To (pseudocode of course):
<DllImport("MY.DLL", EntryPoint:="GetStuff",
CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Ansi)> _
Private Shared Function GetStuff(ByVal szHello As String) As <MarshalAs,
bstr) As BSTRTHINGY$
End Function
In my Dll it's declared like:
Function GetStuff Alias "GetStuff"( szHello As ASCIIZ ) EXPORT AS String
Function = szHello & "hello"
End Function
Note: VB6 does it fine..
- 12
- ASP.Net >> [Personalizable(PersonalizationScope.User)]Hi,
I have to persist the following property on a "per user" basis:
[WebBrowsable(true),Personalizable(PersonalizationScope.User)]
[Personalizable(PersonalizationScope.User)]
public Hashtable listOfViews
{
get
{
return listDict;
}
set
{
listDict = value;
}
}
I can see that the property get persisted (i.e. if I close the browser, open
it again - link to the web part page - my values are there), but the problem
is that - ALL users have access to the SAME property. Thus the property is
not saved on per-user basis - but it is shared among all.
Any ideas on why?
/NeXTstep
- 13
- ASP.Net >> Why is the file being corrupted (using a download tracker)?I set up a download tracker. When i first tested it, all was fine. However
as i just found out via an email, the zip file is corrupt. Folks can
download the file but it just cant be opened. The download code appears to
work fine as far as logging the user and sending the file (as far as i can
tell) but my guess is that there is a problem with the download tracker that
is corrupt ing the file because the file is fine onmy local drive. Any
ideas?
Thanks,
Ashok
Code posted below.
Sub DownloadFile(ByVal forceDownload As Boolean)
Dim productcode As String =
HttpContext.Current.Request.QueryString("ProductCode").ToString
Dim productpath As String
Dim ds As DataSet = dal.ExecuteDataset(dal.RDConn, CommandType.Text, "Select
* From Products Where ProductCode=@ProductCode", "Products", New
OleDb.OleDbParameter("@ProductCode", productcode))
Dim fp As String = ds.Tables(0).Rows(0).Item("ProductPath").ToString
Dim name As String = Path.GetFileName(fp)
Dim ext As String = Path.GetExtension(fp)
dal.ExecuteNonQuery(dal.RDConn, CommandType.Text, "Update Products Set
ProductDownloadCount=ProductDownloadCount + 1 Where
ProductCode=@ProductCode", New OleDbParameter("@ProductCode",
productcode.ToString))
dal.ExecuteNonQuery(dal.RDConn, CommandType.Text, "Insert Into
ProductDLCount (ProductName, ProductCode,DateDownloaded, IPAddress) Values
(@ProductName, @ProductCode, @Date, @IPAddress)", New
OleDbParameter("@ProductName", name.ToString), New
OleDbParameter("@ProductCode", productcode), New OleDbParameter("@Date",
DateTime.Now.ToString("F")), New OleDbParameter(" @IPAddress",
HttpContext.Current.Request.UserHostAddress.ToString))
Dim type As String = ""
' set known types based on file extension
If Not (ext Is Nothing) Then
Select Case ext.ToLower()
Case ".htm", ".html"
HttpContext.Current.Response.ContentType = "text/HTML"
Case ".txt"
HttpContext.Current.Response.ContentType = "text/plain"
Case ".doc", ".rtf"
HttpContext.Current.Response.ContentType = "application/msword"
Case ".zip"
HttpContext.Current.Response.ContentType = "application/zip"
Case ""
HttpContext.Current.Response.ContentType = "application/octet-stream"
End Select
End If
If forceDownload Then
HttpContext.Current.Response.AppendHeader("content-disposition",
"attachment; filename=" + name)
End If
If type <> "" Then
HttpContext.Current.Response.ContentType = type
End If
HttpContext.Current.Response.WriteFile(fp)
HttpContext.Current.Response.End()
- 14
- 15
- ASP.Net >> System.Net.HttpWebRequest questionI don't know if I'm barking up the wrong tree or not, but here goes.
Basically I just want to validate that a URL exists when a user enters it
into our system. Essentially a send out a little request to see if the page
actually loads or if it doesn't exist at all.
I've been using the following code I lifted, but I'm not sure where to take
it from here, or if I have the entirely wrong namespace/concept.
Dim request As HttpWebRequest =
CType(WebRequest.Create("http://www.thissitewontexist.com"), HttpWebRequest)
' Set some reasonable limits on resources used by this request
request.MaximumAutomaticRedirections = 4
request.MaximumResponseHeadersLength = 4
' Set credentials to use for this request.
request.Credentials = CredentialCache.DefaultCredentials
Dim responser As HttpWebResponse
Try
responser = CType(request.GetResponse(), HttpWebResponse)
Catch
' Gets here if it fails, but I'd prefer a cleaner solution
End Try
After this block, StatusCode = OK for sites that worked.
I'm completely lost on how to do this smoothly, any thoughts?
Thanks,
James
|
|
|