|
Hello,
There is a page into my asp.net application which must be requested only by myself (administrator) or by an externel tool like Windows task scheduler, pingdom, curl.exe, and so on.
Because this page contains some code to send e-mail to many users.
When the page is requested par the following url http://www.mysite.com/Send.aspx the code behind do the work.
This page is'nt accessible by my web site interface but it's located at the web site roots.
Is there anyway to protect this page to avoid someone (a non-authorize user) run it???
thank's for your help
|
|
|
|
|
|
When the user click on the button in the datapager (like previous, next, 1,2,3,4,....), it should direct him/her to that page. Without the update panel, it works fine. However, with the update panel, only the first page can be correctly shown. When the users click the button in the datapager, even the listview disappear and I don't know why. I have searched for a few sites but none of them give me a satisfactory result. Am I missing out something? Thank you.
http://www.sendspace.com/file/c8yimj <----the aspx file (Please find the part marked with scriptmanager and update panel)
http://www.sendspace.com/file/nel2xu <---- the c# file (Please begin from the method DataPager1_PreRender
|
|
|
|
|
|
The code are here...
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
<asp:UpdatePanel ID="UpdatePanel1" Updatemode="Always" ChildrenAsTriggers="true" runat="server">
<ContentTemplate>
<asp:ListView ID="ListView1" runat="server"
OnItemCommand="ListView1_OnItemCommand" GroupItemCount="1">
<LayoutTemplate>
<div style="border: solid 1px black">
<table>
<asp:PlaceHolder ID="groupPlaceHolder" runat="server"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<GroupTemplate>
<div>
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</div>
</GroupTemplate>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID="LinkButton1" CommandName="Delete_item" CommandArgument='<%# Eval("entry_no") %>' runat="server" Text="Delete!" />
</td>
</tr>
<tr>
<td>Location: <%#Eval ("location") %></td>
</tr>
<tr>
<td>Type:<%#Eval ("type") %><asp:ImageButton ID="ImageButton1" onClientClick = "Button1_onclick()" runat="server" ImageUrl="play.gif" CommandName="Listen" CommandArgument='<%#Eval("type") %>'/></td>
</tr>
<tr>
<td>Further Description: <%#Eval ("further_description") %><asp:ImageButton ID="Play_btn" runat="server" ImageUrl="play.gif" CommandName="Listen" CommandArgument='<%#Eval("further_description") %>' OnClientClick="popup('popUpDiv')" /></td>
</tr>
<tr>
<td><%# test_item_photo_name(Eval("items_photo_name").ToString()) %></td>
</tr>
<tr>
<td><asp:Button runat="server" Text="Play Recordings" CommandName="Recordings" CommandArgument='<%#Eval("recordings") %>' ID="recordings_btn" Visible="True" />
</tr>
</ItemTemplate>
</asp:ListView>
<asp:DataPager ID="pg" PageSize="1" runat="server" OnPreRender="DataPager1_PreRender" PagedControlID="ListView1">
<Fields>
<asp:NextPreviousPagerField ShowFirstPageButton="True" ShowNextPageButton="False" />
<asp:NumericPagerField />
<asp:NextPreviousPagerField ShowLastPageButton="True" ShowPreviousPageButton="False" />
</Fields>
</asp:DataPager>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</div>
Code behind:
protected void DataPager1_PreRender(object sender, EventArgs e)
{
DataTable result = (DataTable)Session["result"];
ListView1.DataSource = result;
ListView1.DataBind();
}
protected void pg_PagerCommand(object sender, DataPagerCommandEventArgs e)
{
e.NewMaximumRows = e.Item.Pager.MaximumRows;
switch (e.CommandName)
{
case "Previous":
if (e.Item.Pager.StartRowIndex > 0)
e.NewStartRowIndex = e.Item.Pager.StartRowIndex - 1;
break;
case "Next":
e.NewStartRowIndex = e.Item.Pager.StartRowIndex + 1;
break;
}
}
protected void ListView1_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
DataPager dpBottom;
dpBottom = ((ListView)sender).FindControl("pg") as DataPager;
dpBottom.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
ListView1.DataBind();
UpdatePanel1.Update();
}
protected void ListView1_OnItemCommand(object sender, ListViewCommandEventArgs e)
{
Label1.Visible = false;
if (String.Compare(e.CommandName.ToString(), "Recordings") == 0)
{
if (String.Compare(e.CommandArgument.ToString(), "") == 0)
{
Label1.Visible = true;
Label1.Text = "No recordings found.";
}
else
{
String path = Server.MapPath(".") + "\\" + login_hash + "\\others\\" + e.CommandArgument.ToString();
Play(path);
}
}
else
{
if (String.Compare(e.CommandName.ToString(), "Listen") == 0)
{
Speak(e.CommandArgument.ToString());
}
if (String.Compare(e.CommandName.ToString(), "Delete_item") == 0)
{
DataTable result = (DataTable)Session["result"];
for (int i = 0; i < result.Rows.Count; i++)
{
if (result.Rows[i]["entry_no"].ToString() == e.CommandArgument.ToString())
{
if (result.Rows[i]["recordings"].ToString() != "")
{
File.Delete(Server.MapPath(".") + "\\" + login_hash + "\\others\\" + result.Rows[i]["recordings"].ToString());
}
if (result.Rows[i]["items_photo_name"].ToString() != "")
{
File.Delete(Server.MapPath(".") + "\\" + login_hash + "\\images\\item_photo" + result.Rows[i]["items_photo_name"].ToString());
}
DataList1_ItemCommand(sender, null);
}
}
try
{
String query = "delete from items_location where entry_no = " + e.CommandArgument.ToString();
Database.OpenConnection();
Database.BeginTransaction();
Database.Update_Insert(query);
Database.CommitTransaction();
Database.CloseConnection();
ListView1.DataSource = result;
ListView1.DataBind();
Session.Remove("result");
Session["result"] = result;
}
catch (Exception ex)
{
Database.RollBackTransaction();
Database.CloseConnection();
}
}
}
}
|
|
|
|
|
Hi,
I have a flash map in my site, which cannot be displayed inside iframes in other domains. So what I wnat to do, is to check the domain name when the page is loaded and hide the flash map if it's other than my domain.
I have heared that there is a commonly used code for hiding flash in Iphones, that can be useful for me, but I couldn't find it, so maybe sompne can copy the code for me.
Thanks, Ben
|
|
|
|
|
benams wrote: there is a commonly used code for hiding flash in Iphones
Its called not being supported. Flash won't even load on an iPhone, iPod or iPad.
No comment
|
|
|
|
|
two articles on browser detection:
http://peter.michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting[^]
http://jibbering.com/faq/notes/detect-browser/[^]
my recommendation though is to use a javascript framework which will take on most of the work for you. once you have determined your browser you can simply hide the div by setting its css display property to none .
just a note though you might still run into problems with the flash trying to run? I am not a huge fan of flash so I have never tried this route before.
my recommendation would be to add the iframe to your document only after you have determined that the browser supports it.
as if the facebook, twitter and message boards weren't enough - blogged
|
|
|
|
|
Hello,
Into my asp.net application every day i download an xml file and store the values in my database. After did this, i display this xml file using an aspx page. After displaying, an e-mail is sent to 2000 users who are subscribe to this info.
My problem is that i want to dipslay first the page to confirm there is no problem, then send the e-mail but because i use Response.Redirect function my code for sending e-mail is never run. If i send first the e-mail, i must wait for the end (5 minutes) before displaying xml value into my page.
Therefore i would to display my page and execute at the same time the function to send e-mail or sending the e-mail in asynchronous mode.
The part of my code with this problem is the following :
iRes = mydb.DBRecordPublication(strFilename, sDate, snumero, sDoc)
If iRes >= 0 Then
Dim NomMagazine As String = strFilename
Response.Redirect("ShowNews.aspx?News=" & NomMagazine & "&DateNews=" & sDate & "&ConnecString=" & mydb.GetConnectionString())
Dim strRes As String = myMail.SendSommaire(Me.Context)
end if
thanks in advance for any help
|
|
|
|
|
Although you can implement an aysnc page you may be better using Ajax. Display the page with a button to send the emails. The button will call an Ajax function that will send the emails. A side benefit is you can get updates on the number of emails sent, if you code it that way.
No comment
|
|
|
|
|
In a C# 2010 web form application that I will be working on, I want to place a dropdown list control in a detailview control. I do not these that control as one of embedded controls you can use. I do see controls like a hyperlink.
Thus can you tell me or point me to a reference so that I see how to place a dropdown list control within a detailsview control?
|
|
|
|
|
lmgtfy[^]
as if the facebook, twitter and message boards weren't enough - blogged
|
|
|
|
|
Can you show me how to use a range validator for the dropdownlist 2010 webform control I listed below? I want
to make certain a value between 01 and 03 are selected.
Note: I am using a required validator on the web form 2010 control listed below.
<pre>
<asp:DropDownList id="DropDownList1" runat="server">
<asp:ListItem Selected="True">Select a number</asp:ListItem>
<asp:ListItem Value="01" />
<asp:ListItem Value="02" />
<asp:ListItem Value="03" />
</asp:DropDownList>
</pre>
|
|
|
|
|
Did you even read the link I provided in your last post? Did you notice the List of Validation Controls? Did you see the long list of How To links?
We are here to assist but you must also make some effort. Being a successful developer means knowing where and how to look for information. You have been given the where. It's up to you to provide the how.
No comment
|
|
|
|
|
but I was wondering if you could also just do my work for me.
as if the facebook, twitter and message boards weren't enough - blogged
|
|
|
|
|
how to generate id to every click on save button.
and every are assending order
|
|
|
|
|
You need to clarify what it is you are trying to accomplish.
No comment
|
|
|
|
|
Hello. This may or may not be an asp.net question but basically, we have a website & we have a situation where we need to know instantly if any users are viewing the site.
I know I can implement some code to create a session when a user visits the site and then log into the database when that user's session has expired (i.e. he's off the site), but even that wouldn't be completely accurate since session objects wait for about 20 minutes of inactivity before expiring. What I need is be able to determine whether any users are on the site currently, not within the last 20 minutes.
My other thought was perhaps there's some tools on the server itself that can help me with this (we use Windows Server 2003), but I wasn't sure if this was a possibility.
Any ideas on the best way to track this?
Thanks.
|
|
|
|
|
you can track pages loading and unloading via javascript. that way whenever a page loads or unloads you can call some server side code via ajax.
<html>
<body onload="alert('The page was loaded')" onunload="alert('The onunload event was triggered')">
</body>
</html>
as if the facebook, twitter and message boards weren't enough - blogged
|
|
|
|
|
This will cause the event to be called every time the page is loaded, i.e. from a refresh or reload. That would not be useful for the OP.
No comment
|
|
|
|
|
for knowing when things start the best approach then would be to possibly tie it into the Application_Start method in the Global.asax.
However knowing when they have left your sight will have to be tied into the page unLoad event. the problem with that approach is that leaving a page doesn't mean leaving the application, as you could just be leaving for another page in the application. this was why I tied into the page onLoad event but you are right there are other approaches. much like skinning a cat there is always more than one to do it.
Another approach maybe....
Tie into the Application_Start and then have an interval on your pages so that every so many seconds (configurable) a web method is called updating the fact that the user is still on your web page. Many moons ago in this very galazy I worked on a web based chat application that did something very similar.
as if the facebook, twitter and message boards weren't enough - blogged
|
|
|
|
|
The Application_Start event would not be useful either. This event is fired when the application is started or the application pool is recycled. It has nothing to with individual sessions. The Page.Unload event is fired when the ASP.NET engine has completed processing, before the page has been rendered to the client and happens each time the page is processed, such as during a postback. I believe you should review the ASP.NET application and page life-cycles.
No comment
|
|
|
|
|
Mark Nischalke wrote: Page.Unload event
my mistake I was not clear, I was referring to the unload for javascript against the body of the page. When I read this last night I was scratching my head thinking what are you talking about Page.Unload??
when I woke up this morning and read it all again I was like Homer Simpson...
I believe from the Global functions you should be able to find when the session starts. As far as finding when the user leaves the site... Well I think there are many approaches to find this out, each of them with their own download.
If you are trying to get something as close as possible to the real event (the user is no longer at your site) then I imagine you are going to have to tie it all into some interval based javascript code that is calling a server function. For that matter though I wonder if you could also just lower your session timers on the web server and once again use one of the Global functions.
I am sure this would make a great article (one probably already exists) to write sometime.
as if the facebook, twitter and message boards weren't enough - blogged
|
|
|
|
|
You could put code in the SessionStart event to record when the user comes to the site. Or in the Login process if you use that. Capturing when the use leaves the site is more difficult. There have been many discussions here about how to get information when a user leaves a site. You may want to try a little searching here. It does involve JavaScript to call a server method.
No comment
|
|
|
|
|
I am new to working with web forms in 2010. To to that fact, I am wondering if you could tell me what validation control I can use in asp.net for a dropdown list control? Also what code would you use? What event ties the dropdown list control to the validation control?
|
|
|
|