Tuesday, April 20, 2010 by Nate Bross
Someone asked on Stack Overflow:
Wondering the pros and cons for MVC architecture in terms of web application development? And What is the difference between MVC and 3-tire architecture?
I posted the following answer, which was chosen as the accepted answer and received 2 upvotes:
As stated by @Sarfraz Wikipedia is a good starting point for this type of question.
To answer your specific question about the difference between MVC and 3-tier architecture, you need to first understand that MVC is (primarily) a GUI/User-Interface framework and design pattern.
In other words, MVC would be just one tier in your 3-tier architecture, you would still have a “service/business logic” tier and a “persistance/database” tier.
Notable comments
Nate (0 upvotes): Yes, that supports my answer, that MVC would only be a single tier in your multi-tier architecture.
Originally posted on Stack Overflow — 2 upvotes (accepted answer). Licensed under CC BY-SA.
Friday, April 9, 2010 by Nate Bross
I asked this on Stack Overflow:
Is it possible to use this Role Provider AspNetWindowsTokenRoleProvider with ASP.NET FORMS Authentication (via this MembershipProvider System.Web.Security.ActiveDirectoryMembershipProvider)?
It seems to only work with <authentication mode="Windows">, is it possible to use it with FORMS?
background — The objective here is to provide an ASP.NET Forms UX while using Active Directory as the back-end authentication system. If there is another, easy way to do this using built-in technologies, that’s great and I’d like to hear about that as well.
update
I should say that I have the authentication working, what I’m struggling with is adding a level of granular control (such as Roles).
Currently, I have to setup my Active Directory Connection to point to a specific OU in my domain, which limits access to only users physically in that OU — what I’d like is to point my Active Directory connection to my entire domain, and restrict access based on Group Membership (aka Roles) this works if I use Windows Authentication — but I’d like to have the best of both worlds, is this possible without writing my own RoleProvider?
Thomas answered (7 upvotes):
As others have mentioned, you cannot use the ActiveDirectoryMembershipProvider with the AspNetWindowsTokenRoleProvider. If you want to use the ADMP with Forms Authentication, you have a few choices:
-
Use the AuthorizationManager aka AzMan. - AzMan is built into Windows 2003+ and can interact with Active Directory groups. In addition, there is an AuthorizationStoreRoleProvider built into .NET 2.0+ that you can use to interact with it. AzMan works on Task, Operations and Roles wherein presumably your application would be coded to act on specific Tasks which could then be grouped into Operations and you can then create Roles which have authority to perform various Operations. There is a management application that gets installed when you install AzMan that you can use to manage Tasks, Operations and Roles. However, there are some downsides to AzMan. First, the AuthorizationStoreRoleProvider does not recognize Tasks. Rather, it loads the Roles list with a list of Operations. Thus, unless you create a custom version of the provider, your applications would need to seek Operation names instead of Task names. Second, it can be a bear to work with in that interaction, at the lowest level, is still via COM. Unless you want your administrators having to use the AzMan tool, you’ll need to write your own pages to manage Operations, Roles and membership in roles.
-
Use the SqlRoleProvider and map roles to usernames. The advantage of this solution is that it is very simple to implement. You can pretty much use it out of the box since the RoleProvider operates on username and not UserId. In your code you would simply check for IsInRole to determine if the given user had been dropped into a role that your code recognizes. The significant downside is that it is geared on usernames only and not AD groups and thus there is no means for an admin to use the AD tools to manage users. Instead, you have to write a management console to manage role membership. In addition, changing a username at the AD level would require an update to your application’s list of known usernames.
-
Write (or locate) a custom AD RoleProvider that honors AD groups. Writing a custom role provider is not for the faint of heart but doing so lets administrators manage role membership using their existing AD tools.
Originally posted on Stack Overflow — 11 upvotes. Licensed under CC BY-SA.
Thursday, April 8, 2010 by Nate Bross
Someone asked on Server Fault:
Using User Isolation to isolate users, so I have folder like this
\FTP\LocalUser
\FTP\LocalUser\Public
\FTP\domain\me
\FTP\domain\bob
The domain users are able to authenticate, login and see their home directory, but Anonymous users attempt to login as anonymous and then are given the error User cannot log in, home directory inaccessible.
update
Using Process Monitor, I was able to determine that I’m getting access denied errors. Which makes sense, because domain users have access to the UNC Path via Active Directory, but anonymous will not, and its telling me it is impersonating NT AUTHORITY\IUSR — how can I setup IIS FTP to impersonate a specific user if the access type is anonymous?
update 2
Is there a way to allow an IUSR account from MachineA to access a share on MachineB?
I posted the following answer, which was chosen as the accepted answer:
I ended up adding
<anonymousAuthentication enabled="true" userName="LimitedAccessDomainuser" password="pw" />
to the
applicationHost.config
file located at
c:\windows\system32\inetsrv\config\
Originally posted on Server Fault — 0 upvotes (accepted answer). Licensed under CC BY-SA.
Thursday, April 1, 2010 by Nate Bross
Someone asked on Stack Overflow:
.NET: How can I copy the files using Windows “Copy Files” dialog. I need to bulk copy multiple files. Does there exists any .NET 2.0 library/method that allows me to do it in crossplatform manner without invoking Windows platform specific libraries.
Thanks in advance.
I posted the following answer, which was chosen as the accepted answer and received 2 upvotes:
In order to use the “Windows ‘Copy Files’ Dialog” you will be required to invoke “Windows platform specific libraries.”
Originally posted on Stack Overflow — 2 upvotes (accepted answer). Licensed under CC BY-SA.
Tuesday, March 30, 2010 by Nate Bross
Someone asked on Stack Overflow:
The goal is to issue the fewest queries to SQL Server using LINQ to SQL without using anonymous types. The return type for the method will need to be IList. The relationships are as follows:
Parent
Child1 Child2
Grandchild1
Parent > Child1 is a one-to-many relationship
Child1 > Grandchild1 is a one-to-n relationship (where n is zero to infinity)
Parent > Child2 is a one-to-n relationship (where n is zero to infinity)
I am able to eager load the Parent, Child1 and Grandchild1 data resulting in one query to SQL Server.
This query with load options eager loads all of the data, except the sibling data (Child2):
DataLoadOptions loadOptions = new DataLoadOptions();
loadOptions.LoadWith<Child1>(o => o.GrandChild1List);
loadOptions.LoadWith<Child1>(o => o.Parent);
dataContext.LoadOptions = loadOptions;
IQueryable<Child1> children = from child in dataContext.Child1
select child;
I need to load the sibling data as well. One approach I have tried is splitting the query into two LINQ to SQL queries and merging the result sets together (not pretty), however upon accessing the sibling data it is lazy loaded anyway.
Adding the sibling load option will issue a query to SQL Server for each Grandchild1 and Child2 record (which is exactly what I am trying to avoid):
DataLoadOptions loadOptions = new DataLoadOptions();
loadOptions.LoadWith<Child1>(o => o.GrandChild1List);
loadOptions.LoadWith<Child1>(o => o.Parent);
loadOptions.LoadWith<Parent>(o => o.Child2List);
dataContext.LoadOptions = loadOptions;
IQueryable<Child1> children = from child in dataContext.Child1
select child;
exec sp_executesql N'SELECT * FROM [dbo].[Child2] AS [t0]
WHERE [t0].[ForeignKeyToParent] = @p0',N'@p0 int',@p0=1
exec sp_executesql N'SELECT * FROM [dbo].[Child2] AS [t0]
WHERE [t0].[ForeignKeyToParent] = @p0',N'@p0 int',@p0=2
exec sp_executesql N'SELECT * FROM [dbo].[Child2] AS [t0]
WHERE [t0].[ForeignKeyToParent] = @p0',N'@p0 int',@p0=3
exec sp_executesql N'SELECT * FROM [dbo].[Child2] AS [t0]
WHERE [t0].[ForeignKeyToParent] = @p0',N'@p0 int',@p0=4
I’ve also written LINQ to SQL queries to join in all of the data in hopes that it would eager load the data, however when the LINQ to SQL EntitySet of Child2 or Grandchild1 are accessed it lazy loads the data.
The reason for returning the IList is to hydrate business objects.
My thoughts are I am either:
- Approaching this problem the wrong way.
- Have the option of calling a stored procedure?
- My organization should not be using LINQ to SQL as an ORM?
Any help is greatly appreciated.
Thank you,
-Scott
I posted the following answer, which was chosen as the accepted answer and received 14 upvotes:
What you have should be correct, you need to add this dataContext.DeferredLoadingEnabled = false; in addition to the LoadOptions you are already setting.
Originally posted on Stack Overflow — 14 upvotes (accepted answer). Licensed under CC BY-SA.
Friday, March 19, 2010 by Nate Bross
Someone asked on Stack Overflow:
I’d like to create a simple browser client that I’ll to demo the REST API we have implemented on a server. I need basic functionality like
- Create an item on server using POST: client fills up a few parameters and posts
- Get list and display using GET: client sends a query, gets an XML list of items and displays them
I don’t need any fancy UI, this just for an internal quick demo, a reasonable UI is totally OK.
I know C++, Java, and Perl, but no Javascript. Is JS the easiest way to do this (I am time constrained, have about half a day to implement this)? If so, can you point me to a good resource where I can just pick up the pieces I need?
I posted the following answer, which was chosen as the accepted answer and received 2 upvotes:
If you want to write javascript and html/css UI to run in a browser, you could use jQuery and its ajax methods.
$(document).ready(function() {
$.get("your/restful/url/here", function(data) { // do stuff with data here});
$.post("your/restful/url/here", function(data) { // do stuff with data here});
});
You could extend the above even further like this:
$(document).ready(function() {
$("post").click(function() {
$.post("/restful/?parm1=" + $("#input1").val() + "&parm2=" + $("#input2").val() , function(data) { // do stuff with data here});
});
});
<input type="text" id="input1" />
<input type="text" id="input2" />
<input type="submit" id="post">Post</input>
Also, as pointed out in the comments, you could also just simply use your browser to open your RESTful urls.
Originally posted on Stack Overflow — 2 upvotes (accepted answer). Licensed under CC BY-SA.
Thursday, March 18, 2010 by Nate Bross
Someone asked on Stack Overflow:
I have an Entity Data Model that I have created, and its pulling in records from a SQLite DB. One of the Tables is People, I want to override the person.Equals() method but I’m unsure where to go to make such a change since the Person object is auto-generated and I don’t even see where that autogen code resides. I know how to override Equals on a hand made object, its just where to do that on an autogen one.
I posted the following answer, which was chosen as the accepted answer and received 11 upvotes:
You need to create a partial class. Add a new .cs file to your solution, and start it like this:
public partial class Person
{
public override bool Equals(Object obj)
{
//your custom equals method
}
}
Originally posted on Stack Overflow — 11 upvotes (accepted answer). Licensed under CC BY-SA.
Thursday, March 11, 2010 by Nate Bross
Someone asked on Stack Overflow:
I have a dropdownlist box on my page.. with A B C D E F each pages have different images.
Once If I select A I need display one Image like B I need to display other image/table on the page.
Can any one tel me how to do this?
I posted the following answer, which was chosen as the accepted answer:
I’d use jQuery, quick example to get you started:
$('#dropDownList').change(
function() {
$('#contentDiv').html("<img src='yourjpg.jpg' alt='alt text' />");
});
You will want to check some values and pick the correct jpg based on the value selected, but that should get you started.
Originally posted on Stack Overflow — 0 upvotes (accepted answer). Licensed under CC BY-SA.
Tuesday, March 2, 2010 by Nate Bross
Someone asked on Stack Overflow:
on a page with textbox control, lets say this textbox is disabled on server side page load. What would happen if a javascript tries to set visibility of the textbox to false ?
Edit: Can the textbox be hidden by javascript even though it’s disabled ?
TIA
I posted the following answer, which was chosen as the accepted answer and received 1 upvote:
Yes, setting disabled on the serverside only adds the disabled attribute.
Originally posted on Stack Overflow — 1 upvotes (accepted answer). Licensed under CC BY-SA.
Thursday, February 25, 2010 by Nate Bross
I asked this on Stack Overflow:
Is there any advantage to having a single monster .css file that contains style elements that will be used on almost every page?
I’m thinking that for ease of management, I’d like to pull out different types of CSS into a few files, and include every file in my main <link /> is that bad?
I’m thinking this is better
- positions.css
- buttons.css
- tables.css
- copy.css
vs.
- site.css
Have you seen any gotchas with doing it one way vs. the other?
Marc Edwards answered (100 upvotes):
A CSS compiler like Sass or LESS is a great way to go. That way you’ll be able to deliver a single, minimised CSS file for the site (which will be far smaller and faster than a normal single CSS source file), while maintaining the nicest development environment, with everything neatly split into components.
Sass and LESS have the added advantage of variables, nesting and other ways to make CSS easier to write and maintain. Highly, highly recommended. I personally use Sass (SCSS syntax) now, but used LESS previously. Both are great, with similar benefits. Once you’ve written CSS with a compiler, it’s unlikely you’d want to do without one.
http://lesscss.org
http://sass-lang.com
If you don’t want to mess around with Ruby, this LESS compiler for Mac is great:
http://incident57.com/less/
Or you could use CodeKit (by the same guys):
http://incident57.com/codekit/
WinLess is a Windows GUI for comipiling LESS
http://winless.org/
Notable comments
Chase Florell (4 upvotes): @FrankPresenciaFandos doing this is ok’ish for a low traffic site, but running this script over and over on high traffic sites seems a little off. If you use a build script, you can have the best of both worlds and still maintain a performant web server since it’s not running the php script (ever).
Originally posted on Stack Overflow — 295 upvotes. Licensed under CC BY-SA.