.net-4.0

A potentially dangerous Request.Path value was detected from the client (?) with valid URL

蓝咒 提交于 2020-01-01 11:58:11
问题 I have an ASP.NET MVC 4 Web Application running on IIS 7.5 for a few weeks now and I noticed that just recently I have been getting quite a lot of the following errors: System.Web.HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (?). at System.Web.HttpRequest.ValidateInputIfRequiredByConfig() at System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext context) I know that this exception is caused when the URL path contains

Abstract class cannot be sealed in c#?

给你一囗甜甜゛ 提交于 2020-01-01 09:45:36
问题 I read somewhere "Abstract and Sealed modifiers are equivalent to a class which is static" I also found that "When you declare a static class, internally the compiler marks the class abstract and sealed, and creates a private constructor in the IL code" so, I decided to do this: static class A { public static void test() { Console.WriteLine("test"); } } Now, the class "A" cannot be inherited nor instantiated. So, let us write a class B using abstract to prevent instantiation and using sealed

How to use Routing ASP.NET 4 WebForms with Query String?

跟風遠走 提交于 2020-01-01 09:18:53
问题 First, this is not MVC, WebForms only.. I'm using routing to keep my site backwards compatible for our clients, while make my project organized. I'm also thinking of moving our encrypted query string to a more friendly url. How this works is our clients have to bookmark a huge encrypted url to prevent them from guessing our other clients by changing an id around. But instead of having this huge url, wanted to add a route like LoginClientName.aspx for each client and have the encrypted query

How to set collection inline?

末鹿安然 提交于 2020-01-01 08:58:47
问题 For example: DataTable table = new DataTable() { Columns = new DataColumnCollection( { new DataColumn("col1"), new DataColumn("col2") }) }); 回答1: You are talking about the Collection Initialiser feature added in C# 3. It is done like this: DataTable table = new DataTable() { Columns = { new DataColumn("col1"), new DataColumn("col2") } }; This does not call a collection constructor, it uses the collection which already exists in the DataTable. This is short-hand for Columns.Add(), so it doesn

How to check if a generic parameter is dynamic in .NET 4.0

那年仲夏 提交于 2020-01-01 08:26:09
问题 I have a class ObjectMapper<T> . Is there any way in .NET 4.0 to tell if typeof(T) is dynamic ? I want to be able to determine inside a member method whether the class was initialized as new ObjectMapper<dynamic>() vs. new ObjectMapper<SomeConcreteClass>() . 回答1: You do this by checking if an instance is of type IDynamicMetaObjectProvider or you can check whether the type implements IDynamicMetaObjectProvider . 回答2: There is no CLR type called dynamic . The C# compiler makes all dynamic

Does Parallel.ForEach require AsParallel()

那年仲夏 提交于 2020-01-01 08:02:57
问题 ParallelEnumerable has a static member AsParallel . If I have an IEnumerable<T> and want to use Parallel.ForEach does that imply that I should always be using AsParallel ? e.g. Are both of these correct (everything else being equal)? without AsParallel : List<string> list = new List<string>(); Parallel.ForEach<string>(GetFileList().Where(file => reader.Match(file)), f => list.Add(f)); or with AsParallel ? List<string> list = new List<string>(); Parallel.ForEach<string>(GetFileList().Where

Does Parallel.ForEach require AsParallel()

百般思念 提交于 2020-01-01 08:02:14
问题 ParallelEnumerable has a static member AsParallel . If I have an IEnumerable<T> and want to use Parallel.ForEach does that imply that I should always be using AsParallel ? e.g. Are both of these correct (everything else being equal)? without AsParallel : List<string> list = new List<string>(); Parallel.ForEach<string>(GetFileList().Where(file => reader.Match(file)), f => list.Add(f)); or with AsParallel ? List<string> list = new List<string>(); Parallel.ForEach<string>(GetFileList().Where

MembershipProvider in .NET 4.0

自闭症网瘾萝莉.ら 提交于 2020-01-01 07:56:52
问题 How can I add the MembershipProvider class to my .NET 4.0 project in VS 2010 B2? I want to customize a MembershipProvider, but I cannot without adding this class. Please guide me through this process. 回答1: Interesting. However, build errors are your friend ;) Attempting to build a class library built as you describe, I get the following build error: The type name 'MembershipProvider' could not be found. This type has been forwarded to assembly 'System.Web.ApplicationServices, Version=4.0.0.0,

MembershipProvider in .NET 4.0

為{幸葍}努か 提交于 2020-01-01 07:56:30
问题 How can I add the MembershipProvider class to my .NET 4.0 project in VS 2010 B2? I want to customize a MembershipProvider, but I cannot without adding this class. Please guide me through this process. 回答1: Interesting. However, build errors are your friend ;) Attempting to build a class library built as you describe, I get the following build error: The type name 'MembershipProvider' could not be found. This type has been forwarded to assembly 'System.Web.ApplicationServices, Version=4.0.0.0,

Parallel calculation of BigInteger factorial

五迷三道 提交于 2020-01-01 07:03:07
问题 As a part of my BigDecimal library, I need to calculate the factorial of any given non negative integer. So I'm using .Net 4.0 's System.Numerics.BigInteger to be able to store huge numbers. Here is the function I'm using: private BigInteger Factorial(BigInteger x) { BigInteger res = x; x--; while (x > 1) { res *= x; x--; } return res; } It's working but not optimized. Now I want to use parallel computing, so here is what I've tried: (I have no experience with parallel programming) public