English 中文(简体)
伙伴关系的厨师和会议问题。 净额
原标题:Questions about cookies and sessions in ASP.net application

我撰写了一份书刊。 允许匿名者进行祈祷,而其他人则评论/确认为这些目的祈祷。 祷告存放在2008年SQ服务器数据库,有独特的识别资料。

他们使用重复控制器和隐蔽的现场储存电网。 复文中的每一件都含有一个纽芬兰语,允许匿名者祷告,这在数据库中被作为反射手段而增加。

基本上,一旦用户证实他/她正在为这个项目祈祷,我就希望解脱ton子,显示该行的总数。

我的理解是,我可以把数据储存在厨师/会堂上,因此,我迄今可以提出的唯一解决办法是将电网储存在其中一个物体上,然后在我的重复控制范围内使用习惯逻辑来检查是否存在。

谁能对如何以最有效率的方式完成像这样的事情提供某种见解? 如果除厨师或会议外还有其他选择,我也很高兴听到。

EDIT: I am trying to implement this solution using the following logic.

准则背后:

protected bool IsPrayerInCookie(string prayerId)
    {
        if(Request.Cookies["prayers"][prayerId] != null)
        {
            return false;
        }
        else
        {
            return true;
        }
    }

ASPX:

 <span class="confirmed_prayers"><span class="trans">
                            <asp:Label runat="server" ID="lblConfirmedPrayers" Text= <%# Eval("ConfirmedPrayers") %>  />
                            people have prayed for this.</span></span>
                            <% if(!IsPrayerInCookie(Eval("PrayerId").ToString())) 
                                {   
                            %>
                                <asp:LinkButton ID="btnPray" CssClass="but_styled" runat="server" TabIndex="8" CommandName="IncrementPrayer">
                                <span><span class="check">
                                    Pray for This</span></span></asp:LinkButton>
                            <%
                                }
                            %>

然而,这只字不行。 谁能帮助我了解如何使x子档案中的陈述工作恰当地把该代码放在正确的国际发展法后面?

问题回答

Session will only last as long as the user is on the site. Therefore, if they close their browser and come back, it will be gone.

库克群岛将是更好的选择,只有它们清除它们的 co,这些数据才会得到。

如果你不要求用户登录,我想这是大家可以做到的。

Heres the MSDN page on cookies:

rel=“nofollow”>http://msdn.microsoft.com/en-us/library/ms178194.aspx

For the actual cookie storage, I would do something like:

Response.Cookies["prayerlist"][CurrentPrayerItemID].Value = "something"; //All that matters is that they have the cookie with this ID.
Response.Cookies["prayerlist"].Expires = DateTime.MaxValue;

因此,当有人点击添加该项目时,你首先要检查一下,看他们是否已经在他们的 co中这样做了。

if(Response.Cookies["prayerlist"][CurrentPrayerItemID] != null)
{
    Response.Cookies["prayerlist"][CurrentPrayerItemID].value = "something";

    // Add prayer to Database
}

And likewise, you would check the cookie whenever you bind the repeater. If they have that cookie, you would disable the corresponding pray button.

我不敢肯定如何处理这一问题,因为我 how问你们的约束力,但我会看一下这样的情况:

foreach(Item item in YourListOfItemsThatYouAreBindingToTheRepeater)
{
    if(Response.Cookies["prayerlist"][CurrentPrayerItemID] != null)
    {
        //Disable Button - Set "HasPrayed" = true
    }
}

要想真正消除纽芬兰语,那么,在您的名单上,如果是伪造的话,那么在 as页上,我们会这样做:

<asp:Button ID="button1" runat="server" Enabled= <%# !(bool)Eval("HasPrayed") %>  />

Using !(bool)Eval("HasPrayed") since you want to set enabled to false if HasPrayed is true.

你可以利用会议储存用户点击的祈祷物品,但是,如果他们回到你的现场,就会忘记以前的所有物品,因为会议已经丢失。

In this case you can use a cookie to store all the prayer item ids that the user has clicked the "I ll pray for this" button. I d go this route if you don t want to require user logins.

For the code you re describing, I think you could use an ASP.NET UpdatePanel which will allow you to update/show the number of people praying for the item and to disable the button.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签