ASP.NET MVC 3 ile özet kimlik doğrulaması gerçekleştirmem gerekiyor. Bu amaçla AuthorizeAttribute ve HttpUnauthorizedResult öğesinden miras aldım. kod aşağıdaki gibidir:HttpUnauthorizedResult türetilmiş sınıfında bulunmayan ExecuteResult yöntemi
public class DefaultController: Controller {
[SessionAuthorize]
public ViewResult Index() {
return View();
}
}
yüzden özel bir şey yapmaz şu şekildedir: kontrolör/eylem için
[AttributeUsage (AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class SessionAuthorize: AuthorizeAttribute {
public override void OnAuthorization (AuthorizationContext actionContext) {
try {
if (null != actionContext.HttpContext.Request.Headers["Authorization"])
// authorization is on the way
// <...>
else
actionContext.Result = new HttpDigestUnauthorizedResult();
} catch (Exception ex) {
Trace.TraceWarning ("SessionAuthorize.OnAuthorization failed: {0}", ex.Message);
}
base.OnAuthorization (actionContext);
}
}
public class HttpDigestUnauthorizedResult: HttpUnauthorizedResult {
public HttpDigestUnauthorizedResult() : base() {
}
public override void ExecuteResult (ControllerContext context) {
if (context == null)
throw new ArgumentNullException ("context");
// this is supposed to initialize digest authentification exchange
context.HttpContext.Response.AddHeader ("WWW-Authenticate", string.Format ("Digest realm=\"somerealm\",qop=\"auth\",nonce=\"{0}\",opaque=\"{1}\""/*, <...>*/));
base.ExecuteResult (context);
}
}
Kod olduğunu. Ancak, ExecuteResult
geçersiz kılındı ancak hiçbir zaman yalnızca standart 401 sayfa döndürülür. Burada neyi özlüyorum? ExecuteResult
nereden aranmalıdır?
Teşekkürler, sorunun tam olarak nerede olduğuydu. –