This is something that bugged me for a while, there is also quite a bit of confusion online about how to do it.
If you need to enable and disable client side validation for fields that become visible/hidden on a form as user fills out the form it is actually quite easy to do.
jQuery.validator.defaults.ignore = ":hidden";
Basically this will cause jquery validation to ignore hidden fields in your form, which is what you want if they are hidden.
Source: MVC unobtrusive validation – conditionally disable/enable validation
When creating stored procedures you will want the identity of the newly inserted row returned.
It’s quite simple, just use SCOPE_IDENTITY.
CREATE PROCEDURE CreateClient
-- Add the parameters for the stored procedure here
@ClientName nvarchar(MAX), @ClientAcronym nvarchar(MAX)
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
INSERT INTO Clients
public int Create(Client entity)
using (SqlConnection connection = new SqlConnection(Settings.SQL_CONNECTION_STRING))
using (SqlCommand cmd = new SqlCommand("CreateClient", connection))
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@ClientName", entity.Username));
cmd.Parameters.Add(new SqlParameter("@ClientAcronym", entity.Email));
var id = cmd.ExecuteScalar();
catch (Exception ex)
// TODO: Log error
Remember, ExecuteScalar is important here. It gives you back your identity.
There seems to be some confusion online in regards to how you restrict a user based on domain when using Windows Authentication.
It can be done in the config file, in my case it was my Web.Config file.
<authentication mode="Windows" />
<allow roles="DOMAIN\Domain Users"/>
<deny users="*" />
Where you see DOMAIN put in the domain you want to allow, leave the user as Domain Users.
You can do this for multiple domains, works a charm!
Source: mvc windows authentication allow all users from domain