public HttpStatusCode GetWebpageStatusCode(Uri url, RequiredAccess requiredAccess) { HttpWebRequest req = ((HttpWebRequest)(WebRequest.Create(url))); req.Proxy = new WebProxy(); req.Proxy.Credentials = CredentialCache.DefaultCredentials; if (requiredAccess == RequiredAccess.Member) { req.CookieContainer = GetSecurityCookie(false); } else if (requiredAccess == RequiredAccess.Admin) { req.CookieContainer = GetSecurityCookie(true); } HttpWebResponse resp = null; try { resp = ((HttpWebResponse)(req.GetResponse())); return(resp.StatusCode); //if (resp.StatusCode == HttpStatusCode.OK) //{ // if (url.ToString().ToLower(CultureInfo.CurrentCulture).IndexOf("redirect", StringComparison.CurrentCulture) == -1 && // url.ToString().ToLower(CultureInfo.CurrentCulture).IndexOf(resp.ResponseUri.AbsolutePath.ToLower(CultureInfo.CurrentCulture), StringComparison.CurrentCulture) == -1) // { // return HttpStatusCode.NotFound; // } //} } catch (System.Exception ex) { while (!(ex == null)) { Console.WriteLine(ex.ToString()); Console.WriteLine("INNER EXCEPTION"); ex = ex.InnerException; } throw; } finally { if (!(resp == null)) { resp.Close(); } } return(resp.StatusCode); }
/// <summary> /// Constructor. /// </summary> public AuthorizationAttribute(RequiredAccess accessRequired) { AccessRequired = accessRequired; }
public HttpStatusCode GetWebpageStatusCode(Uri url, RequiredAccess requiredAccess) { HttpWebRequest req = ((HttpWebRequest)(WebRequest.Create(url))); req.Proxy = new WebProxy(); req.Proxy.Credentials = CredentialCache.DefaultCredentials; if (requiredAccess == RequiredAccess.Member) req.CookieContainer = GetSecurityCookie(false); else if (requiredAccess == RequiredAccess.Admin) req.CookieContainer = GetSecurityCookie(true); HttpWebResponse resp = null; try { resp = ((HttpWebResponse)(req.GetResponse())); return resp.StatusCode; //if (resp.StatusCode == HttpStatusCode.OK) //{ // if (url.ToString().ToLower(CultureInfo.CurrentCulture).IndexOf("redirect", StringComparison.CurrentCulture) == -1 && // url.ToString().ToLower(CultureInfo.CurrentCulture).IndexOf(resp.ResponseUri.AbsolutePath.ToLower(CultureInfo.CurrentCulture), StringComparison.CurrentCulture) == -1) // { // return HttpStatusCode.NotFound; // } //} } catch (System.Exception ex) { while (!(ex == null)) { Console.WriteLine(ex.ToString()); Console.WriteLine("INNER EXCEPTION"); ex = ex.InnerException; } throw; } finally { if (!(resp == null)) { resp.Close(); } } return resp.StatusCode; }