ASP.NET core JWT authentication always throwing 401 unauthorized

Keep in mind that the UseAuthentication, UseRouting and UseAuthorization middleware must in correct in order for the ASP framework properly inject the identity context to http request. It should look like this: (.NET Core 3.1) Edit: the same code applies to .NET 5 & .NET 6 app.UseAuthentication(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); });

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

How to add a “confirm delete” option in ASP.Net Gridview?

This should do it. I found it here: http://forums.asp.net/p/1331581/2678206.aspx <asp:TemplateField ShowHeader=”False”> <ItemTemplate> <asp:ImageButton ID=”DeleteButton” runat=”server” ImageUrl=”~/site/img/icons/cross.png” CommandName=”Delete” OnClientClick=”return confirm(‘Are you sure you want to delete this event?’);” AlternateText=”Delete” /> </ItemTemplate> </asp:TemplateField>

Deploying ASP.NET MVC4 App to GoDaddy Compiler issue

I have struggled with the same problem for months. And finally solved it. In the plesk on godaddy I changed the ASP.Net settings. First changed CAS-trustlevel to Full. Then I changed in the Web.config of my project the following: Add trust level full to the system.web Remove the compilers in the system.codecom <system.web> compilation debug=”true” … Read more

What’s the difference between implementing FilterAttribute, IActionFilter and inheriting from ActionFilterAttribute in asp.net mvc 3?

Basically FilterAttribute provides the most low level behaviour of MVC Attributes and implements the IMvcFilter that provides the Order and AllowMultiple properties. ActionFilterAttribute is the basis for filtering actions and results, since is a implementation of IActionFilter, IResultFilter and inherit from FilterAttribute. Your MySecondFilterAttribute implementation leads to ActionFilterAttribute without IResultFilter capabilities (OnResultExecuting and OnResultExecuted).

Which authentication and authorization schemes are you using – and why?

Actually, the answer is probably a combination of 1 and 3. You can take advantage of a lot of the tools and features that the framework provides for you by writing a membership, role or profile provider if the default options don’t quite go as far as you’d like. We’ve done just that on a … Read more

How does Page.IsValid work?

Validation occurs after Page_Load, but before event handlers (See http://msdn.microsoft.com/en-us/library/ms178472(v=VS.100).aspx). If your button does not cause validation, you must manually fire Page.Validate. You may not interrogate Page.IsValid until after (1) you have called Page.Validate or (2) a control that causes validation was the source of/included in a postback. If you require validation to occur before … Read more

Does every ‘HttpRequest’ get its own thread in ASP.NET?

If you’re referring to using the HttpRequest object for making outgoing requests from your application, no – HttpRequest runs in the current thread. If you’re referring to how IIS and ASP.NET handles threading per request, yes. Each request is run on a separate thread. However, the model is a little more complex than that – … Read more

What are the pros and cons of running IIS as 32bit vs 64bit on a 64bit OS?

The only perf advantage to running IIS on 64bit vevrsus 32-bit is to allow access to a much larger memory address space. If you are doing normal ASPX page processing, then it’s likely you don’t need to address more than 4gb from any single process. Suppose you run in 32-bit mode with a web-garden with … Read more