How to Customize ASP.NET Web API AuthorizeAttribute for Unusual Requirements

The best solution for my scenario appears to be bypass the base OnAuthorization completely. Since I have to authenticate each time cookies and caching the principle are not of much use. So here is the solution I came up with: public override void OnAuthorization(HttpActionContext actionContext) { string username; string password; if (GetUserNameAndPassword(actionContext, out username, out … Read more

Windows Authentication for ASP.NET MVC 4 – how it works, how to test it

For IIS 8.5 and MVC 4: How does Windows Authentication work? In this mode, User.Identity (as in HttpContext.Current.User.Identity) is populated by the underlying web server. This might be IIS Express in the link from @R Kumar demonstrated, or full blown IIS as in the video by @Thomas Benz. Specifically, User.Identity is a WindowsIdentity object. E.g. … Read more

What are the Web.Debug.config and Web.Release.Config files for?

It’s the new Web.config transformation feature of Visual Studio 2010. More information here. Edit: Are these files used to specify debug and release specific settings, so you don’t clutter up the main web.config? It isn’t limited to three files, you could (in theory) have as many files as you have environments. The “top level” Web.config … Read more

ASP.Net MVC 4 Form with 2 submit buttons/actions

That’s what we have in our applications: Attribute public class HttpParamActionAttribute : ActionNameSelectorAttribute { public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo) { if (actionName.Equals(methodInfo.Name, StringComparison.InvariantCultureIgnoreCase)) return true; var request = controllerContext.RequestContext.HttpContext.Request; return request[methodInfo.Name] != null; } } Actions decorated with it: [HttpParamAction] public ActionResult Save(MyModel model) { // … } [HttpParamAction] public ActionResult … Read more

List all active ASP.NET Sessions

You can collect data about sessions in global.asax events Session_Start and Session_End (only in in-proc settings): private static readonly List<string> _sessions = new List<string>(); private static readonly object padlock = new object(); public static List<string> Sessions { get { return _sessions; } } protected void Session_Start(object sender, EventArgs e) { lock (padlock) { _sessions.Add(Session.SessionID); } … Read more

The transaction manager has disabled its support for remote/network transactions

Make sure that the “Distributed Transaction Coordinator” Service is running on both database and client. Also make sure you check “Network DTC Access”, “Allow Remote Client”, “Allow Inbound/Outbound” and “Enable TIP”. To enable Network DTC Access for MS DTC transactions Open the Component Services snap-in. To open Component Services, click Start. In the search box, … Read more