How to Authorize different login Url in MVC3?

Hello everyone I have two login but how can I assign these login URLs with using authorize ?

Here is my webconfig :

 <location path="Home">
    <system.web>
      <authorization>
        <deny users="?"/>
      </authorization>
    </system.web>  
  </location>


 <authentication mode="Forms">
      <forms loginUrl="~/Home/Login" timeout="2880" />
    </authentication>

So how can I create second loginurl ?

Answers


You cannot have 2 logon urls in Forms Authentication. If you need to achieve this functionality you could write custom [Authorize] attributes and then override the HandleUnauthorizedRequest method where you could redirect to the corresponding logon url.

For example:

public class MyAuthorizeAttribute : AuthorizeAttribute
{
    private readonly string _controller;
    private readonly string _action;
    public MyAuthorizeAttribute(): this("account", "logon")
    {
    }

    public MyAuthorizeAttribute(string controller, string action)
    {
        _controller = controller;
        _action = action;
    }

    protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
    {
        var values = new RouteValueDictionary(new
        {
            controller = _controller,
            action = _action,
            returnurl = filterContext.HttpContext.Request.Url.PathAndQuery
        });
        filterContext.Result = new RedirectToRouteResult(values);
    }
}

and then:

public class SomeController
{
    [MyAuthorize]
    public ActionResult Foo()
    {
        return View();
    }

    [MyAuthorize("account", "someotherlogonaction")]
    public ActionResult Bar()
    {
        return View();
    }
}

Need Your Help

NSAttributedString text position

objective-c ios6 nsattributedstring

I sub-classed a UILabel, so I can use this TitleLabel on several places. This TitleLabel has a custom font. The lineheight is set with an NSAttributedString.

how to repeat entire table in while loop

php mysql while-loop repeat

I have a code which repeats rows while loop, but how can i repeat the entire table in while loop.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.