authorize

How to restrict access to a certain file in MVC

好久不见. 提交于 2019-12-08 06:44:30
I am using ASP.Net MVC, and I was wondering how can I restrict access to a certain file. I read about using [Authorize] but it applies to controllers and actions. I try to use within the web.config but its extremely advise not to do that cause MVC becomes confuse when seeing multiple . My file is within the base of the application, e.g. /MyApp/MyFile. I would like to do is, when a user navigates to the file. The user will see, correct me if I'm wrong, the HTTP 401 error or something. In order to do this stick the files in a folder under App_Data which will prevent direct access and then you

How to restrict access to a certain file in MVC

天大地大妈咪最大 提交于 2019-12-08 04:57:16
问题 I am using ASP.Net MVC, and I was wondering how can I restrict access to a certain file. I read about using [Authorize] but it applies to controllers and actions. I try to use within the web.config but its extremely advise not to do that cause MVC becomes confuse when seeing multiple . My file is within the base of the application, e.g. /MyApp/MyFile. I would like to do is, when a user navigates to the file. The user will see, correct me if I'm wrong, the HTTP 401 error or something. 回答1: In

Delphi Download File with WinInet with UserName and Password

你。 提交于 2019-12-08 04:14:17
问题 There are numerous articles of how to download a file using WinInet (that's where I got the code from), but they all seem to be older and/or closed. Downloading without a username and password works fine, but if I protect the folder (Using VodaHost) with username and password I keep getting an authentication error when trying to download a file: 401 Unauthorized...... If I access through a web browser the username/password dialog pops up and I can get in fine. The folder protected is: http:/

One JWT token for many services

半世苍凉 提交于 2019-12-07 22:16:22
问题 I am facing the problem with JWT Authentication in ASP.Net Core. The scenario looks following: I have a ASP.NET Core Web API, let's call it 'API A'. It is resonsible for generating JWT Token to user who provide correct login/password, then token is generating. I have second ASP.NET Core Web Api, called 'API B' which returns some data from database. I would like to be able to use JWT token, generated by 'API A' to authorize access to data from 'API B'. Is it possible to achieve it by using

MVC 3 Authorize custom roles

孤街醉人 提交于 2019-12-07 15:17:02
问题 I am new MVC 3 user and I am trying to make admin through SQL database. First of all, I have Customer entity and admin can be defined through admin field which is boolean type in Customer entity. I want to make to access admin only in Product page, not normal customer. And I want to make [Authorize(Roles="admin")] instead of [Authorize]. However, I don't know how can I make admin role in my code really. Then in my HomeController, I written this code. public class HomeController : Controller {

Asp MVC [Authorize] to return a Post instead of a Get

亡梦爱人 提交于 2019-12-06 16:22:07
I would like to use [Authorize(Roles="Admin")] tags on my controller methods. If a user is not an admin I would like to return this user to my login screen. The default behaviour of returning the user to my login page is reroute my user to "Account/Login" using a Get url. The problem is, my website's subpages are all partial views refreshed by Ajax calls, including my login screen. So my question is: Is it possible to alter the class below to return a post redirect instead of a get redirect? public class AjaxAuthorizeAttribute : AuthorizeAttribute { override public void OnAuthorization

Is the [Authorize] attribute for ASP.NET MVC controllers only for Membership Providers?

蓝咒 提交于 2019-12-06 00:58:56
问题 Does the [Authorize] attribute used with ASP.NET MVC controllers only function with sites that have implemented a MembershipProvider? 回答1: Short answer is no. It just checks that there is a IPrincipal, how that gets there is up to you. I have my own login logic that I use instead of the Membership provider, once I've authenticated a user I just call the FormsAuthentication.SetAuthCookie method. Once you've done that you can then use the [Authenticate] attribute. 回答2: The [Authorize] attribute

MVC 3 Authorize custom roles

半城伤御伤魂 提交于 2019-12-05 20:42:18
I am new MVC 3 user and I am trying to make admin through SQL database. First of all, I have Customer entity and admin can be defined through admin field which is boolean type in Customer entity. I want to make to access admin only in Product page, not normal customer. And I want to make [Authorize(Roles="admin")] instead of [Authorize]. However, I don't know how can I make admin role in my code really. Then in my HomeController, I written this code. public class HomeController : Controller { [HttpPost] public ActionResult Index(Customer model) { if (ModelState.IsValid) { //define user whether

MVC 4 Forms Authentication not working with [Authorize]

青春壹個敷衍的年華 提交于 2019-12-05 06:16:43
I'm learning MVC4 right now, and I am following the Pro ASP NET MVC4 4th edition book to create a Sports Store project. I have always developed in webforms, and I am trying to figure out how the forms authentication is working in MVC4. Here is what I have achieved: Web.Config <authentication mode="Forms"> <forms loginUrl="~/Account/Login" timeout="2880"/> </authentication> AccountController login Action: [HttpPost] public ActionResult Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid) { if (authProvider.Authenticate(model.UserName, model.Password)) { return Redirect

Check authorize in SignalR attribute

左心房为你撑大大i 提交于 2019-12-05 03:28:06
i have some services on ServiceStack and use SignalR in this project. And now, i would like to secure hub connection (access only for authenticated users), but i use ServiceStack framework authentication.. (not asp.net authentication) and ServiceStack's sessions (write AuthUserId ih this session and authentication flag). So, when user trying connect to the hub -- hub must to check authentication... (yes, i can request Cookies from Hub (method OnConnected, for example), but SignalR check authentication in Authorize Attribute - and i must do it in this class (not in hub) ( http://www.asp.net