authorize

More control on ASP.Net MVC's Authorize; to keep AJAX requests AJAXy

允我心安 提交于 2019-11-30 02:29:55
I have some action methods behind an Authorize like: [AcceptVerbs(HttpVerbs.Post), Authorize] public ActionResult Create(int siteId, Comment comment) { The problem I have is that I'm sending a request through AJAX to Comment/Create with X-Requested-With=XMLHttpRequest which helps identify the request as AJAX. When the user is not logged in and hits the Authorize wall it gets redirected to /Account/LogOn?ReturnUrl=Comment%2fCreate which breaks the AJAX workflow. I need to be redirected to /Account/LogOn?X-Requested-With=XMLHttpRequest Any ideas how that can be achieved? Any ways to gain more

ASP.NET MVC custom authorization

孤者浪人 提交于 2019-11-29 16:29:08
问题 I am building a web application using ASP.NET MVC that has two very distinct types of users. I'll contrive an example and say that one type is content producers (publishers) and another is content consumers (subscribers). I am not planning on using the built-in ASP.NET authorization stuff, because the separation of my user types is a dichotomy, you're either a publisher or a subscriber, not both. So, the build-in authorization is more complex than I need. Plus I am planning on using MySQL. I

What is the best mechanism to implement granular security (i.e. authorization) in an ASP.NET MVC application?

会有一股神秘感。 提交于 2019-11-29 01:52:41
Suppose a high-speed developer was tasked with building a banking application which would be accessed by many different people. Each person would want to access his or her own account information but would not want others to access it. I would like to know the best practice for restricting access in an MVC application so that only the user who owns the information (or an administrator) could access it. The Authorize attribute allows us to restrict by role. While this is a starting point, it seems that any authenticated user could gain access to any other user's information. ActionFilters seem

More control on ASP.Net MVC's Authorize; to keep AJAX requests AJAXy

南楼画角 提交于 2019-11-29 00:10:04
问题 I have some action methods behind an Authorize like: [AcceptVerbs(HttpVerbs.Post), Authorize] public ActionResult Create(int siteId, Comment comment) { The problem I have is that I'm sending a request through AJAX to Comment/Create with X-Requested-With=XMLHttpRequest which helps identify the request as AJAX. When the user is not logged in and hits the Authorize wall it gets redirected to /Account/LogOn?ReturnUrl=Comment%2fCreate which breaks the AJAX workflow. I need to be redirected to

Authorization and ASP.NET MVC Caching

╄→гoц情女王★ 提交于 2019-11-28 08:46:12
I'm confused on ASP.NET MVC caching and authorization and in dire need of some clarification. My self-made authorization attribute inherits from AuthorizeAttribute . Its overridden AuthorizeCore method runs every time, even if I set an [OutputCache] attribute on a controller action. I understand that part. Now the mind bender for me: AuthorizeCore will fail every time now when I actually do output caching and the page is served from the cache. The reason is that when the request is cached, the httpContext.Session supplied with AuthorizeCore is null !? Here's some simplified code: protected

Authorize attribute and jquery AJAX in asp.net MVC

こ雲淡風輕ζ 提交于 2019-11-26 04:43:27
问题 I have used jquery ajax function to submit a form. The users have to be logged in else they must redirect to a login page.I have used Authorize() attribute for it. [Authorize] public ActionResult Creat() { .... } If the user is not login the action return login page to jquery\'s ajax functions and it is displayed on the same page but I want to redirect the user to login page. Is there any solution? 回答1: Working example: https://github.com/ronnieoverby/mvc-ajax-auth Important parts:

Override Authorize Attribute in ASP.NET MVC

我是研究僧i 提交于 2019-11-26 03:47:49
I have an MVC controller base class on which I applied the Authorize attribute since I want almost all of the controllers (and their actions along) to be authorized. However I need to have a controller and an action of another controller unauthorized. I wanted to be able to decorate them with the [Authorize(false)] or something but this is not available. Any ideas? Edit: Since ASP.NET MVC 4 the best approach is simply to use the built-in AllowAnonymous attribute. The answer below refers to earlier versions of ASP.NET MVC You could create a custom authorisation attribute inheriting from the

Override Authorize Attribute in ASP.NET MVC

血红的双手。 提交于 2019-11-26 01:14:22
问题 I have an MVC controller base class on which I applied the Authorize attribute since I want almost all of the controllers (and their actions along) to be authorized. However I need to have a controller and an action of another controller unauthorized. I wanted to be able to decorate them with the [Authorize(false)] or something but this is not available. Any ideas? 回答1: Edit: Since ASP.NET MVC 4 the best approach is simply to use the built-in AllowAnonymous attribute. The answer below refers