|
I don't get it here. I've always used HttpCookies to store multiple values in them
But using Cookie, it seems you can only store 1 value.
What I'm trying to do:
I have a mvc view called Bug Report. You click the button and it runs the Diag Controller with an action that uses HttpWebRequest and prior was WebClient. I changed it to transmit a cookie in the header, because WebClient was too basic.
On the page that is getting read, I have an home made security attrubute that uses OnActionExecuting and the ActionExecutingContext. If the request doesn't contain the session variable, it gets kicked out to Logout.
So to the best of my research, you can make a cookie container with multiple cookies.
This works fine, but I wanted to refine it more...
With HttpCookies, I can send 1 cookie with the 4 values, but with cookie, I have to send each cookie separate. I don't understand this part.
CookieContainer container = new CookieContainer();<br />
container.Add(new Cookie("a", httpCookie["a"]) { Domain = target.Host });
container.Add(new Cookie("b", httpCookie["b"]) { Domain = target.Host });
container.Add(new Cookie("c", httpCookie["c"]) { Domain = target.Host });
container.Add(new Cookie("d", "true") { Domain = target.Host });
var webRequest = (HttpWebRequest)WebRequest.Create(rUrl);
webRequest.CookieContainer = container;
using (var response = (HttpWebResponse)webRequest.GetResponse())
{
model.Page_HTML = response.ToString();
}
So I wrote this, the main cookie, but I can't figure out how to store 4 records in it.
Cookie cookie = new Cookie() {
Name = "Main",
Expires = DateTime.Now.AddMinutes(1),
Domain = target.Host,
HttpOnly = true,
Secure = true
};
On the OnActionExecuting side, I figured how to read the cookies. But it seems sort or silly to read 4 cookies. It looks like on this side I can just read a HttpCookie of any format.
HttpCookie cookie_A = filterContext.RequestContext.HttpContext.Request.Cookies.Get("a");
So my question is:
Am I beating a dead horse with a stick here and I should just be happy that the 4 cookies work?
If it ain't broke don't fix it
|
|
|
|
|
Multi-valued cookies are not a standard feature. The HttpCookie class "fakes" support by serializing the values to a string similar to a query string:
HttpCookie - Reference Source[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks Richard!
So in other words, an HttpCookie write can write an array of values that is parsed when read by HttpCookie.
Sort of a way to make cookies easier for beginners and take the complexity out of it, or for compatibility with some other standard written by other programs. Or maybe proprietary to just reading our own cookies in asp.net - most likely answer. Sort of like those dumb html objects in webforms.
And perhaps cookie is the standard way to read and write a cookie.
Glad I didn't beat the horse more with my stick on the subject.
If it ain't broke don't fix it
|
|
|
|
|
Hi,
I have a Kendo grid I am have a dropdown as the first element of it, I want to get the selected text or value of those all drop downs if they are selected. If they are not selected there is no need to count them.
I am using jQuery to do it, tried many options so far there is no luck. Grid is very big, hence I am just putting only the code where I am trying to access it.
This is is how I am trying it, so far no luck, any help would be very helpful, thanks in advance.
var grid = $( "#budgetdGrid" );
var dataSource = grid.dataSource;
var columns = $("#budgetdGrid").data("kendoGrid").columns;
var rows = $("#budgetdGrid").data("kendoGrid").rows;
var noOfCols = columns.length;
grid.items().each(function(a) {
alert(a.text())
});
I am trying to access it within this function:
function onLineDropDownChange(e) {<br />
//alert(e.sender.select())
//alert(e.sender.text());
var grid = $( "#budgetdGrid" );
var dataSource = grid.dataSource;
var columns = $("#budgetdGrid").data("kendoGrid").columns;
var rows = $("#budgetdGrid").data("kendoGrid").rows;
var noOfCols = columns.length;
grid.items().each(function(a) {
alert(a.text())
});
//alert(e.sender.select().val())
//rows.each(function(e) {
// var grid = $("#budgetdGrid").data("kendoGrid");
// var dataItem = grid.dataItem(this);
// alert(dataItem);
//})
var tr = this.element.closest("tr");
var line_no="";
var prev_line = [];
// var line_arr = ['200', '201', '101a-cw', '101a-mc', '70p-cw', '70p-mc'];
var lin_val = tr.find("input[id^='inputLine_']").val();
if ( lin_val != "" && lin_val != 'undefined') {
line_no = tr.find("input[id^='inputLine_']").data("kendoDropDownList").text().substr(0, tr.find("input[id^='inputLine_']").data("kendoDropDownList").text().indexOf('('));
}
if (lin_val != '' && line_no != '') {
$("#doeGrid").find("#budgetdGrid tbody").find('tr').each(
function () {
var id = $(this).find("input[id^='inputLine_']").val();
if (id == lin_val && lin_val != "" && id != "") {
prev_line.push(id);
}
});
if (prev_line.length > 1) {
alert("You have already selected the Line Item in the previous rows");
}
else {
if ((line_no.substr(0, line_no.indexOf('-')) == '200') || (line_no.substr(0, line_no.indexOf('-')) == '201') || (line_no == '101a-cw') ||
(line_no == '101a-mc') || (line_no == '70p-cw') || (line_no == '70p-mc') || (line_no.substr(0, line_no.indexOf('-')) == '202' && '@Session["FiscalYearCode"]'=='FY 2015-2016')||
(line_no.substr(0, line_no.indexOf('-')) == '204' && '@Session["FiscalYearCode"]'=='FY 2015-2016')||
(line_no.substr(0, line_no.indexOf('-')) == '203' && '@Session["FiscalYearCode"]'=='FY 2015-2016') ||
(line_no.substr(0, line_no.indexOf('-')) == '205' && '@Session["FiscalYearCode"]'=='FY 2015-2016'))
//if (containsLine(line_no, line_arr))
{
if (containsAny('@Model.Service_Code', [30, 33, 34, 43, 51, 52]) && '@Model.Program_Code' >= 87) {
tr.find("input[name^='txt_budgt']").removeAttr("disabled = 'disabled'");
tr.find("input[name=txt_IndivUOS]").removeAttr("disabled = 'disabled'");
}
else if (('@Model.Service_Code' == 48 && '@Model.Program_Code' >= 87)) {
tr.find("input[name^='txt_budgt']").removeAttr("disabled = 'disabled'");
tr.find("input[name=txt_IndivUOS]").removeAttr("disabled = 'disabled'");
tr.find("input[name=txt_NtpGrp]").removeAttr("disabled = 'disabled'");
tr.find("input[name=txt_NtpDos]").removeAttr("disabled = 'disabled'");
}
else {
tr.find("input[name^='txt_budgt']").removeAttr("disabled = 'disabled'");
}
}
else if (('@Session["FiscalYearCode"]'=='FY 2016-2017') || ('@Session["FiscalYearCode"]'=='FY 2017-2018'))
{
tr.find("input[name^='txt_dirCst']").removeAttr("disabled = 'disabled'");
}
else {
tr.find("input[name^='txt_budgt']").removeAttr("disabled = 'disabled'");
}
}
}
else {
alert("Please Choose Proper Line Item");
}
}
This function will be called when there is any change in the Grid, onchange but when change occurs it has to loop through the whole grid and then find out the selected text or values of the dropdowns then it will be acted upon the selected items of the dropdowns.
Please any help would be very very supportive - thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
|
I don't have membership for Telerik forum, only licensed members are eligible to put questions, I am also searching but if somebody can help me, it would be a great help - thanks buddy.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
indian143 wrote: only licensed members are eligible to put questions
But surely only licensed members are eligible to use the controls?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yes but my Company has the license not me, hence the problem Rick (do you go with Rick or Richard)
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Hi,
I could able to get up to here so far but the val or text functions are not working on those items. Here is the below code I did,
var dataSource = $("#budgetdGrid").data("kendoGrid").dataSource;
var data = dataSource.data(); // or this.view();
for (var i = 0; i < data.length; i++) {
alert(data[i][0].val());
}
But the alert(data[i][0].val()); is throwing error, I tried with text also, that one also is throwing errors saying that those functions are not supported etc. budgetdGrid is the Kendo Grid, and the first element of that (I mean index) 0 is dropdown list selected text I want to get, for all the rows, I am looping through rows correctly here that the number of rows 8 are matching with what I have in Grid, but I am not able to get the selected items text value.
Any help would be greatly helpful, thanks in advance.
I have tried in the following way also, but its pulling out only the value but not the selected text, I need the selected text rather than value because I need to compare with text but not with the value:
$("#doeGrid").find("#budgetdGrid tbody").find('tr').each(
function () {
var id = $(this).find("input[id^='inputLine_']").val();
var txt = $(this).find("input[id^='inputLine_']").text();
alert(id);
alert(txt)
if (id == lin_val && lin_val != "" && id != "") {
prev_line.push(id);
}
});
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
-- modified 21-Mar-18 14:19pm.
|
|
|
|
|
I have a gridview with a score column (4).
I am trying to get the total score.
Thanks anyone..please
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID,EP,supEmail" DataSourceID="SQLDuties" OnPreRender="GridView1_PreRender" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" Visible="False" />
<asp:TemplateField HeaderText="Duties" SortExpression="Duties">
<EditItemTemplate>
<asp:Label ID="EditDuties" runat="server" Text='<%# Bind("Duties") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Duties") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Agreed" SortExpression="Agreed">
<EditItemTemplate>
<asp:Label ID="EditTargets" runat="server" Text='<%# Bind("Agreed") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Agreed") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Score (1-5)" SortExpression="Score">
<EditItemTemplate>
<asp:TextBox ID="txtScore" runat="server" Text='<%# Bind("Score") %>' TextMode="Number"></asp:TextBox>
<asp:RequiredFieldValidator ID="RFVScore" runat="server" ErrorMessage="Score Require" ControlToValidate="txtScore" ForeColor="red"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator2" runat="server" ErrorMessage="1 to 5" MaximumValue="5" MinimumValue="1" ControlToValidate="txtScore" ForeColor="red"></asp:RangeValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Score") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Comment" HeaderText="Comment" SortExpression="Comment" />
<asp:BoundField DataField="EP" HeaderText="EP" SortExpression="EP" Visible="False" />
<asp:BoundField DataField="supEmail" HeaderText="supEmail" SortExpression="supEmail" Visible="False" />
</Columns>
<EmptyDataTemplate>
<br />
</EmptyDataTemplate>
</asp:GridView>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int total = 0;
if (e.Row.RowType == DataControlRowType.DataRow)
{
total = total + Convert.ToInt32( e.Row.Cells[4].Text.ToString());
}
Response.Write(total.ToString());
}
|
|
|
|
|
e.Row.Cells[4].Text will only work for BoundField Columns. For accessing TemplateFields , you need to use FindControl() method. For example:
var score = ((Label)e.Row.Cells[4].FindControl("Label3")).Text;
|
|
|
|
|
I am hoping someone can explain to me the rationale behind the Page.RegisterStartupScript method... What does it achieve that simply writing your script to a Literal doesn't? I've never had a reason to use it - if I want to add JavaScript to a page I simply do that. I am no doubt being very silly, but..
|
|
|
|
|
It ensures the script is only registered once.
For example, if you have a UserControl, you could have multiple instances of it on the page. Writing the script to a literal would output one copy of the script for each instance of the control, whereas RegisterStartupScript would (normally) only output one copy.
It also ensures that the script is rendered at the bottom of the form, rather than scattered throughout the markup. Not a huge issue, but very satisfying if you have OCD.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
OK... so if you have multiple user controls with scripts in then, yes, I see that makes sense. Otherwise though... (and I generally place my literal at the bottom of the page anyway )
Ta.
|
|
|
|
|
In addition to ensuring the script is only written once, if you are writing a user control then you can only control the mark-up inside that control, so it wouldn't be possible to inject a label for js at the bottom of the page.
My biggest issue with RegisterStartupScript etc is the name, it should be changed to RegisterStartupScriptPleaseNoteThatYourJSIsNOTBeingExecutedImmediatelyInServerSideCode
|
|
|
|
|
Hi, I am creating a scheduling website for a university project using Visual Studios. It is a website for managing shifts and schedules and the main event of the website is the scheduler which will display employee shifts within it. I have never created a timetable/calendar/scheduler in Visual Studios before. How can I produce a simple scheduler in C# that can be modified and links to a database?
|
|
|
|
|
|
Hi Vincent,
Thanks for the reply. I have searched Google for resources and I couldn’t find what I wanted; so I turned to forums with the hope that people who have successfully created schedules in Visual Studios could give me their knowledge.
The links that you gave me are just what I need. I will attempt compiling the code and editing it to suit my needs. Thanks again.
|
|
|
|
|
Maybe you could look at quartz.net
and
Hangfire
|
|
|
|
|
i read a article on DDD and also read one on onion architecture from csharpcorner. some how i felt both are same but have different name only.
please some one let me know your thought. if there is any difference then please mention in details. thanks
|
|
|
|
|
I wonder whether this post is a bit misplaced.
Nevertheless, I'm just in a middle of reading Eric Evan's book and I see DDD as a much broader concept than onion architecture. The second one stands for how you organize your application components. Although DDD also to some extent operates with those components and also advocates some patterns (side-effect free functions, specification pattern, bounded-context etc) I would say that the crucial idea behind DDD is a ubiquitous language which is formed by close cooperation between domain experts (here is where the name comes from) and developers.
|
|
|
|
|
I think its same, but I am not very sure about it.
|
|
|
|
|
i am familiar with OAuth but not with open id.
Nowadays many web site allow us to login to their site with facebook, linkedin etc. so when we click on facebook image then we redirected to facebook login page where we provide our facebook credential. if credential is right then facebook redirect us to first site. the advantage is we do not have to create & remember many credentials rather remember one.
but i do not know what is open id and how it works? i read this article http://www.devcurry.com/2012/11/aspnet-mvc-4-external-login-using-openid.html
it seems that in case of both open id and oauth user create their login to external site and user use that credential to other web site to login. if it is right then oauth and open id both are same and doing same purpose. so where is the difference?
please discuss how open id is different from oauth in terms of flow ?
|
|
|
|
|
|
i have seen a forum stackoverflow where user can login with openid and oauth to post their question.
in both case 3rd party validate user and send a token to stackoverflow to get access.
so how we can say openid is authentication system and oauth is authorization system because in case of stackoverflow access both does the same thing.
looking for further discussion. thanks
|
|
|
|