Reputation: 61
Six months ago I wrote a OpenID library. It is trying to authenticate with some open Id and if that is verified by provider, it raises OpenIdValidationSuccess event. I was using some event handlers to handle this events from the page.
OpenMedia.Auth oAuth = new oAuth();
In my Page Load
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// Register event handlers.
oAuth.OpenIdValidationSuccess += new EventHandler(web_Success);
oAuth.OpenIdValidationFailure += new EventHandler(web_Failure);
// Start handling responses.
oAuth.StartHandleResponse();
}
}
So i am new in MVC. I want to use this code library in my new MVC application. But what would be the best practice?
Upvotes: 1
Views: 3801
Reputation: 717
I would think, you should replace the mvc authorize attribute with your custom authorized attribute like this:
public class CustomAuthorizeAttribute : AuthorizeAttribute
{
public override void OnAuthorization(AuthorizationContext filterContext)
{
// base.OnAuthorization(filterContext);
//do your own authorize here
if (filterContext.Result is HttpUnauthorizedResult && filterContext.HttpContext.Request.IsAjaxRequest())
{
//do some more logic here
// filterContext.HttpContext.Response.StatusCode = 200;
//filterContext.Result = new ContentResult() { Content = "404" };
}
}
And then under each action in your controller, you just need to add CustomAuthorizeAttribute attribute instead of the custom one that MVC provided
Upvotes: 0
Reputation:
There are no server controls and server-side events in ASP.NET MVC framework. You need to find another place to put calls to your library. In order to advise you further, you need to explain what your library does and how it integrates with the rest of the application.
Upvotes: 2