ASP.NET is a web application framework developed by Microsoft to allow programmers to build dynamic web sites and web applications.
23
votes
5answers
15k views
Comma delimited string from list of items
Is there a simple way to create a comma delimited string from a list of items without adding an extra ", " to the end of the string?
I frequently need to take an ASP.NET CheckBoxList and format the ...
10
votes
5answers
1k views
ASP.net c# class design (simple)
Here's a class I'm designing:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
namespace Artworking.classes
{
...
9
votes
6answers
5k views
c# image resizing class
how does this class to resize an image look? All comments welcome, no matter how nitty :)
using System;
using System.Collections.Generic;
using System.Web;
using System.Drawing;
using System.IO;
/*
...
9
votes
2answers
524 views
Advice regarding “pluggable” routes in asp.net mvc
How do I handle multi-tenancy with routes in ASP.NET MVC?
The application is a multitenant ASP.NET MVC 3 application. Tenants are identified based on hostname so this does not interfere with routing.
...
8
votes
3answers
290 views
Cleaning up a redundant switch statement
How can I use a more generic method to clean up the redundancy in the switch statement below?
I'm working on an ASP.NET webforms app that will have five identical user controls that I will be showing ...
8
votes
3answers
420 views
Is there a better way to output a javascript array from ASP.net?
I often run into the problem of producing a javascript array on an ASP.net page from an IEnumerable and I was wondering if there was an easier or clearer way to do it than
<% bool firstItem = ...
8
votes
3answers
1k views
ASP.net custom user control design
I've built a custom control that generates a tab style navigation. Each page might have different tabs to display, the aim was to modularise it so I can make global changes to all the tabs.
...
7
votes
3answers
329 views
How to optimize this code to get a instant/better result instead of waiting at least 10 seconds every time?
I have the following code that unfortunately is really slow:
private void FilterSessionByDate()
{
SessionsFilteredByDate =
...
7
votes
2answers
22k views
Basic Simple Asp.net + jQuery + JSON example
Earlier this year, before I learnt about Code Review StackExchange, I gave this answer in response to a question about how to combine ASP.net, jQuery, and JSON: ...
7
votes
3answers
402 views
Is this a good way to catch all 404s in .NET without playing with IIS configuration?
The situation is that its not always possible to play with the web.config or have access to IIS, that being said I had to come up with a way to catch all 404s in a .NET application, for aspx page ...
6
votes
7answers
2k views
Comparing string arrays
My code does what I need it to do, but I think I am missing the "right" way to do this with comparing the arrays. Essentially what I need this to do is compare a textbox entry against two different ...
6
votes
3answers
656 views
My Calendar generation code is slow. How do I improve it?
I have a model I have created to generate iCal and the necessary JSON for the jQuery calendar plugin Full Calendar to work. When I display the page, the JSON generation takes about 7 seconds. The ...
6
votes
1answer
8k views
ASP.Net, C#, and alert/display messages
We have a hidden div in a master page. When we want to display a message, we send a function a message to display, and it turns that div from .Visible false to .Visible true, and fills the div with ...
6
votes
4answers
897 views
3-layer ASP.NET app - Need critique/advice
My current setup is a 3 layered application: UI > BLL > DAL. Each layer is set up as a separate project. The UI is an ASP.Net website and the BLL & DAL are Class Library projects.
I've shown some ...
6
votes
1answer
236 views
Workflow and Design Feedback on an Add / Edit Form
I was looking for advice, feedback and information on best practices when designing ASP.NET Web Forms in a .NET web application.
Allow me to post a sample of how I currently do things. I am omitting ...
5
votes
4answers
394 views
Plese review following methods
private string FormatComments(string comments)
{
//If comments has no space and inserted as a single line then following code will break
//the comments into multiple lines.
...
5
votes
6answers
1k views
Place Try Catch in Business Logic or User Interface
I found the following two types of handling exception in Business Logic Layer.
ASP.NET 3.5 Enterprise Application Development use similar method like the first one (I read it few years ago).
I also ...
5
votes
2answers
648 views
trying to optimize conditional string building
Essentially I'm taking a number of checkboxes off of my view, adding them to a Dictionary<string, bool>, and writing out the Keys of any checkbox that is checked.
I'm guessing there must be a ...
4
votes
10answers
831 views
Is there a better way to do this database insert? Looking for best-practice example.
I wrote the following code to insert records into a database. The user selects the rows from the RadGrid and the insert command is executed when that user clicks the button. I've been spending a lot ...
4
votes
2answers
1k views
General code review - Database Class Creator
Overview
I've written a class that will create c# code. The output is a single .cs file for each table in the default database (the database is defined inside a web.config file). I'm looking for a ...
4
votes
2answers
241 views
Is it a good practice to wrap datatypes in custom classes?
So in my current application, I was thinking to make a extended class for all the datatypes. For int, it will be something like ExtendedInt, for bool it will be something like ExtendedBool.
These ...
4
votes
6answers
451 views
Strategy for avoiding threadpool starvation while performing cpu bound jobs in a queued fashion
My aim is to avoid using threadpool threads for CPU bound work, thus avoiding a situation where IIS stops responding to new requests.
Can you see any problems with the code below? Is this a ...
4
votes
2answers
242 views
Is this a good way to handle Web API UriTemplates?
I want to be able to do /contacts/Matt%20Phillips and /contacts/1 and have both of them return a contact. The way I did that was to try and parse an int from the captured parameter and call the Id ...
4
votes
2answers
3k views
General code review - Database Access class
I'm looking for any comments or feedback on my database access class. Security and speed are two things I'm most concerned about. One thing to note is this class has to work in a c# .net 2 environment ...
4
votes
2answers
625 views
Session Wrapper
I have two types of session wrappers:
Type 1:
public class SessionHandler
{
public static SessionHandler CurrentSession
{
get
{
SessionHandler session =
...
4
votes
2answers
556 views
Optimizing a Fire and Forget page tracker
I have a bit of code that came from Egg Head Cafe a long while ago and it's been working great. But I ran the entire site through Redgate's Profiler. and it came up as the biggest hot spot in my code. ...
4
votes
3answers
518 views
Stackoverflow Like Pager
I've been working on a stackoverflow like pager for my personal use and I've gotten everything working pretty good. Some of my logic is a bit suspect though. Especially the logic in the Pager class ...
4
votes
1answer
938 views
ASP.NET MVC - NHibernate (UoW) + Command pattern?
I'm building a ASP.NET MVC app and would like some feedback for my way to query/execute statements to the ORM.
I'm using Fluent NHibernate, and have mixed the UoW provided by NHibernate with a ...
4
votes
2answers
146 views
Optimization code for checking if a list contains any element ID of another list
I have the following code:
var sessionsWithError = SessionsFilteredByDate
.Where(i => i.TrackerId > 0 && i.StatusId == 0)
.Select(i => i.SessionId);
var ...
4
votes
3answers
143 views
Should this code be in the code behind or separate class?
I'm developing a log-on page where users either select or create an associated organization when they sign up. There can be either 1 user per organization or many users per organization, this is ...
4
votes
2answers
272 views
Is there a better way to consume an ASP.NET Web API call in an MVC controller?
In a new project I am creating for my work I am creating a fairly large ASP.NET Web API. The api will be in a separate visual studio solution that also contains all of my business logic and database ...
4
votes
1answer
2k views
Using RouteValueDictionary to convert anonymous type to query string
I am trying to take advantage of the reflection built into RouteValueDictionary to add values to the query string of a URL. This is what I came up with. It seems to work, but I thought I would post it ...
3
votes
1answer
148 views
return false if one of members fails a condition
I want to validate a list of objects for example strings. and if one of the objects fails to pass the condition return false as validation result . this is the code I use :
public static bool ...
3
votes
3answers
198 views
How below code can be refactored with design pattern?
In one of our project with 3 tier architecture (tightly coupled), there's bad code smell. It doesn't follow DRY principle. I want to refactor it with design possible design pattern. I don't want to ...
3
votes
3answers
1k views
Elegant approach to building unordered list from XML
How can I improve on this rather ugly method that builds an HTML unordered list from an XML file?
I maintain a collection of ASP.NET webforms that all need to pull in the same site navigation as our ...
3
votes
3answers
231 views
How to refactor this property's code?
I have a view model with properties that represent years and months:
public IEnumerable<SelectListItem> Years
{
get
{
return new SelectList(
Enumerable.Range(1900, ...
3
votes
1answer
193 views
Refactor if statements
I am importing an excel document into my project.
I then use the following code to verify that columns have data and display the appropriate error message.
My code is working but it just doesn't ...
3
votes
2answers
220 views
How to improve a try on a dual Mode JavaScript textBox WaterMark?
I was just trying to make an alternate Ajax watermark from "insert date" (first mode) to "mm/dd/yyyy" (second mode).
After some trial and error, I succefully implemented a solution using JavaScript.
...
3
votes
2answers
92 views
Would like feedback and ways to improve my c# ado.net code
I currently have a method in my repository that will run sql and map the reader to objects.
protected IEnumerable<T> Query<T, TFactory>(string sql, List<IDbDataParameter> parameters ...
3
votes
1answer
89 views
Fully utilizing the layers of an n-layered web application
First off, let me say that this article pretty much changed how I program, for the better. Until I read this article, I was a spaghetti programming master --- if there were awards for crappiest, ...
3
votes
1answer
590 views
ASP.NET Web API HTTP GET with optional parameters
Writing my first ASP.NET Web API web service. Still learing the power of Linq as well. I feel like there is a more ideomatic way of doing this:
public class StylesController : ApiController
{
...
3
votes
1answer
343 views
Creating a list of pairs after splitting the string containing all of the sets
I am working on asp.net/MVC and I need to read a value from my web.config file. Splitting the list into multiple keys is not an option.
<add key="DepartAssign" value="Depart1:PersonAssignTo1; ...
3
votes
1answer
418 views
Asp.net MVC login method
I wrote this login method:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel logModel, string returnUrl)
{
if (!ModelState.IsValid)
{
...
3
votes
1answer
119 views
Code Review of AsyncPages in ASP.NET 2.0
Could somebody code-review the implementation of Async in ASP.NET 2.0 web form page below and let me know If I am missing something in implementing in a correct way?
AsyncPagesASPNET20.aspx
<%@ ...
3
votes
1answer
302 views
Cross-browser double form submit prevention
We developed a potential solution for the double form submit prevention and we need some review on it. To be able to execute this code on asp.net we needed to add our function call directly into the ...
3
votes
1answer
163 views
C# asp.net project functionalities
I just started working in a project that wasn't developed by me, I'm worried about some of the functionalities and I would like some suggestions.
After the login validations, the login procedure is ...
3
votes
1answer
270 views
Simple search page.
using System;
using System.Web.UI.WebControls;
namespace RideShare.Web
{
public partial class UserOrganization : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs ...
3
votes
1answer
219 views
asp.net (vb.net): handling of open database connection and calling shared function from web api
I'm working on an ASP.NET project using VB.NET that uses Dapper
and the code as implemented so far runs fine with just me testing.
In the example below, Dapper calls a stored proc.
But my I am ...
3
votes
1answer
117 views
Creating an IUserSession that is used throughout my code
I need a bit of help on if I have coded this class correctly.
I want to handle the setting of client cookie/client store.
public class UserSession : IUserSession
{
private readonly ...
3
votes
0answers
631 views
Review of Fluent LinkedIn REST API client interface design
There is a handful of LinkedIn clients written in C# on the NuGet package library, but afaict most only do authentication via LinkedIn. I found a couple which offer a linkedin rest api interface. Of ...
