c#-4.0

Authentication in webAPI

无人久伴 提交于 2020-01-17 04:51:47
问题 I want to set Individual authentication for the web API application i have created in Visual studio 2013 using Asp.net . please tell me how can i do that . VS 2013 by default provide several types of authentication while designing . i choose individual Authentication . But don't know how it works . 回答1: Create authentication token on server-side and store it in your database or even in cache. Then send this token with requests from your win forms application. WebApi should check this token

(413) Request Entity Too Large in WCF

冷暖自知 提交于 2020-01-17 04:44:05
问题 Trying so send Array size of 1227136 and getting error 413 This is how I am sending the data from a wreb application- protected void Page_Load(object sender, EventArgs e) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:59624/RestServiceImpl.svc/PostFileRest");//Path for local request.Timeout = Timeout.Infinite; request.KeepAlive = true; request.ContentType = "application/vnd.ms-excel"; /*---------------------------------------------------------------------------

Internal class masked by object

别等时光非礼了梦想. 提交于 2020-01-17 02:27:07
问题 Assume that class (B)'s public function has the return line: return (object)(new List<A>{Some elements}) where A is an internal and sealed class. I cannot change the code of A or B. After I call this function in B, how do I find the first element of that list. C# does not let me cast that list back into List<A> because A is internal. 回答1: Just because you can read the source code or disassemble the code, you should not rely on the current implementation, rather try to use the public interface

Add sibling after a specific XML node C#

江枫思渺然 提交于 2020-01-17 01:38:08
问题 My xml document looks like this: <root> <parent1> <element1> </element1> </parent1> <parent1> <element1> </element1> </parent1> <parent1> <element1> </element1> </parent1> <parent2> <element1> </element1> </parent2> <parent2> <element1> </element1> </parent2> <parent3> <element2> </element2> </parent3> </root> I would like to add a new parent1 node after the last parent1 node before the first parent2 node. Like this: <root> <parent1> <element1> </element1> </parent1> <parent1> <element1> <

Error when splitting and replacing chars C# email with LINQ Array Index not supported in LINQ

心已入冬 提交于 2020-01-16 20:06:08
问题 This throws an error 'ArrayIndex' is not supported in LINQ to Entities. so what would be an alternative for this as the split and replace fails? from S in db.Students where S.ID = ID select new { S.EMAIL.Split('@')[0].Replace(".", " ,"), S.NAME }; This is for a list of Students and this is how I currently can add them. mylist.DataValueField = "email"; mylist.DataTextField = "name"; This fails: S.EMAIL.Split('@')[0].Replace(".", " ,") Please help. Thanks 回答1: If you want it to run on the SQL

Error when splitting and replacing chars C# email with LINQ Array Index not supported in LINQ

大兔子大兔子 提交于 2020-01-16 20:05:03
问题 This throws an error 'ArrayIndex' is not supported in LINQ to Entities. so what would be an alternative for this as the split and replace fails? from S in db.Students where S.ID = ID select new { S.EMAIL.Split('@')[0].Replace(".", " ,"), S.NAME }; This is for a list of Students and this is how I currently can add them. mylist.DataValueField = "email"; mylist.DataTextField = "name"; This fails: S.EMAIL.Split('@')[0].Replace(".", " ,") Please help. Thanks 回答1: If you want it to run on the SQL

Entity Framework - Common Query

心已入冬 提交于 2020-01-16 19:18:30
问题 referencing at previous post (Entity Wrapper - Custom) I still have some difficult about generic query to retrieving common field. I've a simple interface with one field only. All my entities inheritance from my interface. Then I've a class encapsulating my objectContext typed. Well, now I need to execute a linq query to get my IQuerable object. The following snippet goes on error at building time: public IQueryable<T> GetQuery<T>() where T : IEntity { var query = GetObjectSetSomehow; /

Entity Framework Model Property not update properly

柔情痞子 提交于 2020-01-16 19:13:06
问题 I am having below mentioned 2 models. GeoLocation Model : public class GeoLocation { public GeoLocation() { } public int Id { get; set; } public double Latitude { get; set; } public double Longitude { get; set; } } Provider Model : public class Provider { public Provider() { Id = Guid.NewGuid(); Created = DateTime.Now; } public Guid Id { get; set; } [Required] public string Name { get; set; } public virtual GeoLocation Location { get; set; } } Repository method : public void SetLocation

How to work with object initialization and classes in C#

落花浮王杯 提交于 2020-01-16 19:09:08
问题 I have a class class TestFixture { public string a { get; set; } public int b { get; set; } public int c { get; set; } public string d { get; set; } public string e { get ; set ; } public int f { get; set; } public int g { get; set; } public bool h { get; set; } public string i { get; set; } public bool j { get; set; } public bool k { get; set; } public TestFixture() { e= dosomething(a, b); f= false; g = DateTime.Now.ToString("yyMMddhhmmss"); h= TestName.Equals("1") && b.Equals("2") ? 1000 :

On data binding: LINQ to Entities does not recognize the method 'System.String ToString()' method

有些话、适合烂在心里 提交于 2020-01-16 04:02:24
问题 I'm using LINQ to Entities My GridView is the following : <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowPaging="True" EmptyDataText="No Data" CellPadding="3" CellSpacing="1" AllowSorting="True" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" CssClass="gridview" OnSorting="GridView1_Sorting" HorizontalAlign="Center"> <AlternatingRowStyle