コード例 #1
0
ファイル: Security.cs プロジェクト: myersBR/My-FyiReporting
        public static bool IsValidateRequest(System.Web.HttpResponse Response, System.Web.SessionState.HttpSessionState Session, string tag)
        {

            if (SessionVariables.LoggedIn == false)
            {
                Response.Redirect("Login.aspx", true);
                return false;
            }


            try
            {
               

                string sql = "SELECT role, tag FROM roleaccess WHERE role = @roleid and tag = @tag;";
                SQLiteCommand cmd = new SQLiteCommand();
                cmd.Connection = new SQLiteConnection(Code.DAL.ConnectionString);
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = sql;
                cmd.Parameters.Add("@roleid", DbType.String).Value = SessionVariables.LoggedRoleId;
                cmd.Parameters.Add("@tag", DbType.String).Value = tag;

                DataTable dt = Code.DAL.ExecuteCmdTable(cmd);

                if (dt.Rows.Count == 0)
                {
                    Response.Redirect("Login.aspx", true);
                    return false;
                }

                if (dt.Rows[0]["tag"].ToString() == tag)
                {
                     return true;
                }

            }
            catch (Exception ex)
            {
                Response.Redirect("Login.aspx", true);
                return false;
            }

            Response.Redirect("Login.aspx", true);
            return false;
        }
コード例 #2
0
ファイル: auth.cs プロジェクト: avf2001/tote
        private static void SaveLoginCookie(System.Web.HttpResponse AResponse)
        {
            //serialize the Principal into a String value
            string principalText;
            System.IO.MemoryStream buffer = new System.IO.MemoryStream();
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

            formatter.Serialize(buffer, HttpContext.Current.User);
            buffer.Position = 0;
            principalText = Convert.ToBase64String(buffer.GetBuffer());

            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                1, HttpContext.Current.User.Identity.Name,
                DateTime.Now, DateTime.Now.AddMinutes(20),
                false, principalText);

            string encTicket = FormsAuthentication.Encrypt(ticket);

            AResponse.Cookies.Add( new HttpCookie(FormsAuthentication.FormsCookieName,encTicket));
            //		 Redirect back to original URL.
            //AResponse.Redirect(FormsAuthentication.GetRedirectUrl("", false));
            AResponse.Redirect(HttpContext.Current.Request.RawUrl, false);
        }
コード例 #3
0
ファイル: RequestHandler.cs プロジェクト: FJRLK/WebFile
        public HttpServer.HttpResponse SendResponse( System.Net.HttpListenerRequest req, System.Net.HttpListenerResponse res )
        {
            if ( req.Url.PathAndQuery.Equals( "/" ) )
            {
                res.Redirect( "/Main" );
                return "";
            }

            if ( req.Url.PathAndQuery.StartsWith( "/Main" ) )
            {
                String response = ResourceHelper.GetResourceString( "HtmlPages.MainPage.html" );
                Entities.Shares[] shares = Entities.Shares.List().ToArray();

                Int32 page = 0;

                if ( !String.IsNullOrEmpty( req.QueryString[ "Page" ] ) )
                    Int32.TryParse( req.QueryString[ "Page" ], out page );

                String relPath = ( req.QueryString[ "Path" ] ?? "" );

                if ( relPath.StartsWith( "/" ) )
                    relPath = relPath.Substring( 1 );

                String[] path = relPath.Split( "/".Split(), StringSplitOptions.RemoveEmptyEntries );

                if ( path.Length == 0 || String.IsNullOrEmpty( path[ 0 ] ) )
                {
                    response = response.Replace( "{data.currentpath}", Newtonsoft.Json.JsonConvert.SerializeObject( new Object[] { "Home" } ) ).Replace( "{data.folderList}", Newtonsoft.Json.JsonConvert.SerializeObject( shares.Select( s => new { relPath = '/' + s.Refname.Trim(), Refname = s.Refname.Trim() } ) ) ).Replace( "{data.fileList}", Newtonsoft.Json.JsonConvert.SerializeObject( new Object[] { } ) );
                }
                else
                {
                    settings = WebFile.Entities.Settings.Get();
                    Entities.Shares share = Entities.Shares.Find( path[ 0 ] );
                    String curPath = GetFullPath( relPath, share );
                    if ( IsDirectory( curPath ) )
                    {
                        PageContent content = GetDirectoryContent( path, relPath, share );

                        response = response.Replace( "{data.currentpath}", Newtonsoft.Json.JsonConvert.SerializeObject( path ) ).Replace( "{data.folderList}", Newtonsoft.Json.JsonConvert.SerializeObject( content.Directories ) ).Replace( "{data.fileList}", Newtonsoft.Json.JsonConvert.SerializeObject( content.Files ) );
                    }
                    else
                    {
                        return new HttpServer.HttpResponse
                        {
                            WriteResponse = true,
                            ByteContent = File.ReadAllBytes( curPath ),
                            ContentType = HttpServer.MimeTypeMap.GetMimeType( Path.GetExtension( curPath ) ),
                            FileName = Path.GetFileName( curPath )
                        };
                    }
                }

                return response.Replace( "{title}", "Web File Server | " ).Replace( "{data.allShares}", Newtonsoft.Json.JsonConvert.SerializeObject( shares.Select( s => s.Refname.Trim() ) ) ).Replace( "{data.pageCount}", "0" );
            }

            if ( req.Url.PathAndQuery.StartsWith( "/Content" ) )
            {
                return HandleStaticContent( req );
            }

            return string.Format( "<HTML><BODY>My web page.<br>{0}<br>Request path: {1}</BODY></HTML>", DateTime.Now, req.Url );
        }
コード例 #4
0
ファイル: UrlRewriter.cs プロジェクト: appliedi/MerchantTribe
		public static void RedirectToErrorPage(ErrorTypes errorType, System.Web.HttpResponse response)
		{
			if (errorType == ErrorTypes.Generic) {
				response.Redirect("~/Error");
			}
			else if (errorType == ErrorTypes.Product) {
				response.Redirect("~/Error?type=product");
			}
			else if (errorType == ErrorTypes.Category) {
				response.Redirect("~/Error?type=category");
			}
		}